home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / sprite / RCS / cccp.c,v < prev    next >
Encoding:
Text File  |  1990-07-26  |  156.8 KB  |  6,260 lines

  1. head     1.7;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.7
  10. date     89.11.27.17.55.02;  author shirriff;  state Exp;
  11. branches ;
  12. next     1.6;
  13.  
  14. 1.6
  15. date     89.08.02.13.49.30;  author nelson;  state Exp;
  16. branches ;
  17. next     1.5;
  18.  
  19. 1.5
  20. date     89.06.01.17.02.33;  author rab;  state Exp;
  21. branches ;
  22. next     1.4;
  23.  
  24. 1.4
  25. date     89.05.08.12.34.11;  author rab;  state Exp;
  26. branches ;
  27. next     1.3;
  28.  
  29. 1.3
  30. date     89.05.05.22.47.30;  author jhh;  state Exp;
  31. branches ;
  32. next     1.2;
  33.  
  34. 1.2
  35. date     89.03.12.20.56.33;  author rab;  state Exp;
  36. branches ;
  37. next     1.1;
  38.  
  39. 1.1
  40. date     89.02.24.11.54.22;  author rab;  state Exp;
  41. branches ;
  42. next     ;
  43.  
  44.  
  45. desc
  46. @@
  47.  
  48.  
  49. 1.7
  50. log
  51. @This is a new version.  I also made some changes to
  52. ensure that max_include_len has the right value.
  53. @
  54. text
  55. @/* C Compatible Compiler Preprocessor (CCCP)
  56. Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
  57.                     Written by Paul Rubin, June 1986
  58.             Adapted to ANSI C, Richard Stallman, Jan 1987
  59.  
  60. This program is free software; you can redistribute it and/or modify it
  61. under the terms of the GNU General Public License as published by the
  62. Free Software Foundation; either version 1, or (at your option) any
  63. later version.
  64.  
  65. This program is distributed in the hope that it will be useful,
  66. but WITHOUT ANY WARRANTY; without even the implied warranty of
  67. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  68. GNU General Public License for more details.
  69.  
  70. You should have received a copy of the GNU General Public License
  71. along with this program; if not, write to the Free Software
  72. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  73.  
  74.  In other words, you are welcome to use, share and improve this program.
  75.  You are forbidden to forbid anyone else to use, share and improve
  76.  what you give them.   Help stamp out software-hoarding!  */
  77.  
  78. typedef unsigned char U_CHAR;
  79.  
  80. #include <sys/types.h>
  81. #include <sys/stat.h>
  82. #include <ctype.h>
  83. #include <stdio.h>
  84. #include <signal.h>
  85. #include <alloca.h>
  86.  
  87. #ifndef VMS
  88. #include <sys/file.h>
  89. #ifndef USG
  90. #include <sys/time.h>        /* for __DATE__ and __TIME__ */
  91. #include <sys/resource.h>
  92. #else
  93. #define index strchr
  94. #define rindex strrchr
  95. #include <time.h>
  96. #include <fcntl.h>
  97. #endif /* USG */
  98. #endif /* not VMS */
  99.   
  100. /* VMS-specific definitions */
  101. #ifdef VMS
  102. #include <time.h>
  103. #include <errno.h>        /* This defines "errno" properly */
  104. #include <perror.h>        /* This defines sys_errlist/sys_nerr properly */
  105. #define O_RDONLY    0    /* Open arg for Read/Only  */
  106. #define O_WRONLY    1    /* Open arg for Write/Only */
  107. #define read(fd,buf,size)    VAX11_C_read(fd,buf,size)
  108. #define write(fd,buf,size)    VAX11_C_write(fd,buf,size)
  109. #ifdef __GNUC__
  110. #define BSTRING            /* VMS/GCC supplies the bstring routines */
  111. #endif /* __GNUC__ */
  112. #endif /* VMS */
  113.  
  114. #define max(a,b) ((a) > (b) ? (a) : (b))
  115.  
  116. /* External declarations.  */
  117.  
  118. void bcopy (), bzero ();
  119. int bcmp ();
  120. extern char *getenv ();
  121. extern char *version_string;
  122.  
  123. /* Forward declarations.  */
  124.  
  125. struct directive;
  126. struct file_buf;
  127. struct arglist;
  128. struct argdata;
  129.  
  130. int do_define (), do_line (), do_include (), do_undef (), do_error (),
  131.   do_pragma (), do_if (), do_xifdef (), do_else (),
  132.   do_elif (), do_endif (), do_sccs (), do_once ();
  133.  
  134. struct hashnode *install ();
  135. struct hashnode *lookup ();
  136.  
  137. char *xmalloc (), *xrealloc (), *xcalloc (), *savestring ();
  138. void fatal (), fancy_abort (), pfatal_with_name (), perror_with_name ();
  139.  
  140. void macroexpand ();
  141. void dump_all_macros ();
  142. void conditional_skip ();
  143. void skip_if_group ();
  144. void output_line_command ();
  145. /* Last arg to output_line_command.  */
  146. enum file_change_code {same_file, enter_file, leave_file};
  147.  
  148. int grow_outbuf ();
  149. int handle_directive ();
  150. void memory_full ();
  151.  
  152. U_CHAR *macarg1 ();
  153. char *macarg ();
  154.  
  155. U_CHAR *skip_to_end_of_comment ();
  156. U_CHAR *skip_quoted_string ();
  157.  
  158. #ifndef FATAL_EXIT_CODE
  159. #define FATAL_EXIT_CODE 33    /* gnu cc command understands this */
  160. #endif
  161.  
  162. #ifndef SUCCESS_EXIT_CODE
  163. #define SUCCESS_EXIT_CODE 0    /* 0 means success on Unix.  */
  164. #endif
  165.  
  166. /* Name under which this program was invoked.  */
  167.  
  168. char *progname;
  169.  
  170. /* Nonzero means handle C++ comment syntax and use
  171.    extra default include directories for C++.  */
  172.  
  173. int cplusplus;
  174.  
  175. /* Current maximum length of directory names in the search path
  176.    for include files.  (Altered as we get more of them.)  */
  177.  
  178. int max_include_len;
  179.  
  180. /* Nonzero means copy comments into the output file.  */
  181.  
  182. int put_out_comments = 0;
  183.  
  184. /* Nonzero means don't process the ANSI trigraph sequences.  */
  185.  
  186. int no_trigraphs = 0;
  187.  
  188. /* Nonzero means print the names of included files rather than
  189.    the preprocessed output.  1 means just the #include "...",
  190.    2 means #include <...> as well.  */
  191.  
  192. int print_deps = 0;
  193.  
  194. /* Nonzero means don't output line number information.  */
  195.  
  196. int no_line_commands;
  197.  
  198. /* Nonzero means inhibit output of the preprocessed text
  199.    and instead output the definitions of all user-defined macros
  200.    in a form suitable for use as input to cccp.  */
  201.  
  202. int dump_macros;
  203.  
  204. /* Nonzero means give all the error messages the ANSI standard requires.  */
  205.  
  206. int pedantic;
  207.  
  208. /* Nonzero means warn if slash-star appears in a comment.  */
  209.  
  210. int warn_comments;
  211.  
  212. /* Nonzero means warn if there are any trigraphs.  */
  213.  
  214. int warn_trigraphs;
  215.  
  216. /* Nonzero means try to imitate old fashioned non-ANSI preprocessor.  */
  217.  
  218. int traditional;
  219.  
  220. /* Nonzero causes output not to be done,
  221.    but directives such as #define that have side effects
  222.    are still obeyed.  */
  223.  
  224. int no_output;
  225.  
  226. /* I/O buffer structure.
  227.    The `fname' field is nonzero for source files and #include files
  228.    and for the dummy text used for -D and -U.
  229.    It is zero for rescanning results of macro expansion
  230.    and for expanding macro arguments.  */
  231. #define INPUT_STACK_MAX 200
  232. struct file_buf {
  233.   char *fname;
  234.   int lineno;
  235.   int length;
  236.   U_CHAR *buf;
  237.   U_CHAR *bufp;
  238.   /* Macro that this level is the expansion of.
  239.      Included so that we can reenable the macro
  240.      at the end of this level.  */
  241.   struct hashnode *macro;
  242.   /* Value of if_stack at start of this file.
  243.      Used to prohibit unmatched #endif (etc) in an include file.  */
  244.   struct if_stack *if_stack;
  245.   /* Object to be freed at end of input at this level.  */
  246.   U_CHAR *free_ptr;
  247. } instack[INPUT_STACK_MAX];
  248.  
  249. /* Current nesting level of input sources.
  250.    `instack[indepth]' is the level currently being read.  */
  251. int indepth = -1;
  252. #define CHECK_DEPTH(code) \
  253.   if (indepth >= (INPUT_STACK_MAX - 1))                    \
  254.     {                                    \
  255.       error_with_line (line_for_error (instack[indepth].lineno),    \
  256.                "macro or #include recursion too deep");        \
  257.       code;                                \
  258.     }
  259.  
  260. /* Current depth in #include directives that use <...>.  */
  261. int system_include_depth = 0;
  262.  
  263. typedef struct file_buf FILE_BUF;
  264.  
  265. /* The output buffer.  Its LENGTH field is the amount of room allocated
  266.    for the buffer, not the number of chars actually present.  To get
  267.    that, subtract outbuf.buf from outbuf.bufp. */
  268.  
  269. #define OUTBUF_SIZE 10    /* initial size of output buffer */
  270. FILE_BUF outbuf;
  271.  
  272. /* Grow output buffer OBUF points at
  273.    so it can hold at least NEEDED more chars.  */
  274.  
  275. #define check_expand(OBUF, NEEDED)  \
  276.   (((OBUF)->length - ((OBUF)->bufp - (OBUF)->buf) <= (NEEDED))   \
  277.    ? grow_outbuf ((OBUF), (NEEDED)) : 0)
  278.  
  279. struct file_name_list
  280.   {
  281.     struct file_name_list *next;
  282.     char *fname;
  283.   };
  284.  
  285. /* #include "file" looks in source file dir, then stack. */
  286. /* #include <file> just looks in the stack. */
  287. /* -I directories are added to the end, then the defaults are added. */
  288.  
  289. /*
  290.  * Use different default include directories for Sprite.  The second
  291.  * default directory gets filled in once the machine type is known.
  292.  */
  293.  
  294. #define GCC_INCLUDE_DIR "/sprite/lib/include"
  295. #define GPLUSPLUS_INCLUDE_DIR "/sprite/lib/include"
  296.  
  297. struct file_name_list include_defaults[] =
  298.   {
  299. #ifdef sprite
  300.     { 0, 0 },
  301.     { 0, GCC_INCLUDE_DIR },
  302. #else       
  303. #ifndef VMS
  304.     { &include_defaults[1], GCC_INCLUDE_DIR },
  305.     { &include_defaults[2], "/usr/include" },
  306.     { 0, "/usr/local/include" }
  307. #else
  308.     { &include_defaults[1], "GNU_CC_INCLUDE:" },       /* GNU includes */
  309.     { &include_defaults[2], "SYS$SYSROOT:[SYSLIB.]" }, /* VAX-11 "C" includes */
  310.     { 0, "" },    /* This makes normal VMS filespecs work OK */
  311. #endif /* VMS */
  312. #endif /* sprite */
  313.   };
  314.  
  315. /* These are used instead of the above, for C++.  */
  316. struct file_name_list cplusplus_include_defaults[] =
  317.   {
  318. #ifdef sprite
  319.     { 0, 0 },
  320.     { 0, GPLUSPLUS_INCLUDE_DIR },
  321. #else
  322. #ifndef VMS
  323.     /* Pick up GNU C++ specific include files.  */
  324.     { &cplusplus_include_defaults[1], GPLUSPLUS_INCLUDE_DIR },
  325.     /* Use GNU CC specific header files.  */
  326.     { &cplusplus_include_defaults[2], GCC_INCLUDE_DIR },
  327.     { 0, "/usr/include" }
  328. #else
  329.     { &cplusplus_include_defaults[1], "GNU_GXX_INCLUDE:" },
  330.     { &cplusplus_include_defaults[2], "GNU_CC_INCLUDE:" },
  331.     /* VAX-11 C includes */
  332.     { &cplusplus_include_defaults[3], "SYS$SYSROOT:[SYSLIB.]" },
  333.     { 0, "" },    /* This makes normal VMS filespecs work OK */
  334. #endif /* VMS */
  335. #endif /* sprite */
  336.   };
  337.  
  338. struct file_name_list *include = 0;    /* First dir to search */
  339.     /* First dir to search for <file> */
  340. struct file_name_list *first_bracket_include = 0;
  341. struct file_name_list *last_include = 0;    /* Last in chain */
  342.  
  343. /* List of included files that contained #once.  */
  344. struct file_name_list *dont_repeat_files = 0;
  345.  
  346. /* List of other included files.  */
  347. struct file_name_list *all_include_files = 0;
  348.  
  349. /* Structure allocated for every #define.  For a simple replacement
  350.    such as
  351.        #define foo bar ,
  352.    nargs = -1, the `pattern' list is null, and the expansion is just
  353.    the replacement text.  Nargs = 0 means a functionlike macro with no args,
  354.    e.g.,
  355.        #define getchar() getc (stdin) .
  356.    When there are args, the expansion is the replacement text with the
  357.    args squashed out, and the reflist is a list describing how to
  358.    build the output from the input: e.g., "3 chars, then the 1st arg,
  359.    then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg".
  360.    The chars here come from the expansion.  Whatever is left of the
  361.    expansion after the last arg-occurrence is copied after that arg.
  362.    Note that the reflist can be arbitrarily long---
  363.    its length depends on the number of times the arguments appear in
  364.    the replacement text, not how many args there are.  Example:
  365.    #define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and
  366.    pattern list
  367.      { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL }
  368.    where (x, y) means (nchars, argno). */
  369.  
  370. typedef struct definition DEFINITION;
  371. struct definition {
  372.   int nargs;
  373.   int length;            /* length of expansion string */
  374.   U_CHAR *expansion;
  375.   struct reflist {
  376.     struct reflist *next;
  377.     char stringify;        /* nonzero if this arg was preceded by a
  378.                    # operator. */
  379.     char raw_before;        /* Nonzero if a ## operator before arg. */
  380.     char raw_after;        /* Nonzero if a ## operator after arg. */
  381.     int nchars;            /* Number of literal chars to copy before
  382.                    this arg occurrence.  */
  383.     int argno;            /* Number of arg to substitute (origin-0) */
  384.   } *pattern;
  385.   /* Names of macro args, concatenated in reverse order
  386.      with comma-space between them.
  387.      The only use of this is that we warn on redefinition
  388.      if this differs between the old and new definitions.  */
  389.   U_CHAR *argnames;
  390. };
  391.  
  392. /* different kinds of things that can appear in the value field
  393.    of a hash node.  Actually, this may be useless now. */
  394. union hashval {
  395.   int ival;
  396.   char *cpval;
  397.   DEFINITION *defn;
  398. };
  399.  
  400.  
  401. /* The structure of a node in the hash table.  The hash table
  402.    has entries for all tokens defined by #define commands (type T_MACRO),
  403.    plus some special tokens like __LINE__ (these each have their own
  404.    type, and the appropriate code is run when that type of node is seen.
  405.    It does not contain control words like "#define", which are recognized
  406.    by a separate piece of code. */
  407.  
  408. /* different flavors of hash nodes --- also used in keyword table */
  409. enum node_type {
  410.  T_DEFINE = 1,    /* the `#define' keyword */
  411.  T_INCLUDE,    /* the `#include' keyword */
  412.  T_IFDEF,    /* the `#ifdef' keyword */
  413.  T_IFNDEF,    /* the `#ifndef' keyword */
  414.  T_IF,        /* the `#if' keyword */
  415.  T_ELSE,    /* `#else' */
  416.  T_PRAGMA,    /* `#pragma' */
  417.  T_ELIF,    /* `#else' */
  418.  T_UNDEF,    /* `#undef' */
  419.  T_LINE,    /* `#line' */
  420.  T_ERROR,    /* `#error' */
  421.  T_ENDIF,    /* `#endif' */
  422.  T_SCCS,    /* `#sccs', used on system V.  */
  423.  T_IDENT,    /* `#ident', used on system V.  */
  424.  T_SPECLINE,    /* special symbol `__LINE__' */
  425.  T_DATE,    /* `__DATE__' */
  426.  T_FILE,    /* `__FILE__' */
  427.  T_BASE_FILE,    /* `__BASE_FILE__' */
  428.  T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
  429.  T_VERSION,    /* `__VERSION__' */
  430.  T_TIME,    /* `__TIME__' */
  431.  T_CONST,    /* Constant value, used by `__STDC__' */
  432.  T_MACRO,    /* macro defined by `#define' */
  433.  T_DISABLED,    /* macro temporarily turned off for rescan */
  434.  T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */
  435.  T_UNUSED    /* Used for something not defined.  */
  436.  };
  437.  
  438. struct hashnode {
  439.   struct hashnode *next;    /* double links for easy deletion */
  440.   struct hashnode *prev;
  441.   struct hashnode **bucket_hdr;    /* also, a back pointer to this node's hash
  442.                    chain is kept, in case the node is the head
  443.                    of the chain and gets deleted. */
  444.   enum node_type type;        /* type of special token */
  445.   int length;            /* length of token, for quick comparison */
  446.   U_CHAR *name;            /* the actual name */
  447.   union hashval value;        /* pointer to expansion, or whatever */
  448. };
  449.  
  450. typedef struct hashnode HASHNODE;
  451.  
  452. /* Some definitions for the hash table.  The hash function MUST be
  453.    computed as shown in hashf () below.  That is because the rescan
  454.    loop computes the hash value `on the fly' for most tokens,
  455.    in order to avoid the overhead of a lot of procedure calls to
  456.    the hashf () function.  Hashf () only exists for the sake of
  457.    politeness, for use when speed isn't so important. */
  458.  
  459. #define HASHSIZE 1403
  460. HASHNODE *hashtab[HASHSIZE];
  461. #define HASHSTEP(old, c) ((old << 2) + c)
  462. #define MAKE_POS(v) (v & ~0x80000000) /* make number positive */
  463.  
  464. /* Symbols to predefine.  */
  465.  
  466. #ifdef CPP_PREDEFINES
  467. char *predefs = CPP_PREDEFINES;
  468. #else
  469. char *predefs = "";
  470. #endif
  471.  
  472. /* `struct directive' defines one #-directive, including how to handle it.  */
  473.  
  474. struct directive {
  475.   int length;            /* Length of name */
  476.   int (*func)();        /* Function to handle directive */
  477.   char *name;            /* Name of directive */
  478.   enum node_type type;        /* Code which describes which directive. */
  479.   char angle_brackets;        /* Nonzero => <...> is special.  */
  480.   char traditional_comments;    /* Nonzero: keep comments if -traditional.  */
  481.   char pass_thru;        /* Copy preprocessed directive to output file.  */
  482. };
  483.  
  484. /* Here is the actual list of #-directives, most-often-used first.  */
  485.  
  486. struct directive directive_table[] = {
  487.   {  6, do_define, "define", T_DEFINE, 0, 1},
  488.   {  2, do_if, "if", T_IF},
  489.   {  5, do_xifdef, "ifdef", T_IFDEF},
  490.   {  6, do_xifdef, "ifndef", T_IFNDEF},
  491.   {  5, do_endif, "endif", T_ENDIF},
  492.   {  4, do_else, "else", T_ELSE},
  493.   {  4, do_elif, "elif", T_ELIF},
  494.   {  4, do_line, "line", T_LINE},
  495.   {  7, do_include, "include", T_INCLUDE, 1},
  496.   {  5, do_undef, "undef", T_UNDEF},
  497.   {  5, do_error, "error", T_ERROR},
  498. #ifdef SCCS_DIRECTIVE
  499.   {  4, do_sccs, "sccs", T_SCCS},
  500. #endif
  501.   {  6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1},
  502.   {  -1, 0, "", T_UNUSED},
  503. };
  504.  
  505. /* table to tell if char can be part of a C identifier. */
  506. U_CHAR is_idchar[256];
  507. /* table to tell if char can be first char of a c identifier. */
  508. U_CHAR is_idstart[256];
  509. /* table to tell if c is horizontal space.  */
  510. U_CHAR is_hor_space[256];
  511. /* table to tell if c is horizontal or vertical space.  */
  512. U_CHAR is_space[256];
  513.  
  514. #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
  515. #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
  516.   
  517. int errors = 0;            /* Error counter for exit code */
  518.  
  519. /* Zero means dollar signs are punctuation.
  520.    -$ stores 0; -traditional, stores 1.  Default is 1 for VMS, 0 otherwise.
  521.    This must be 0 for correct processing of this ANSI C program:
  522.     #define foo(a) #a
  523.     #define lose(b) foo(b)
  524.     #define test$
  525.     lose(test)    */
  526. #ifndef DOLLARS_IN_IDENTIFIERS
  527. #define DOLLARS_IN_IDENTIFIERS 0
  528. #endif
  529. int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
  530.  
  531. FILE_BUF expand_to_temp_buffer ();
  532.  
  533. DEFINITION *collect_expansion ();
  534.  
  535. /* Stack of conditionals currently in progress
  536.    (including both successful and failing conditionals).  */
  537.  
  538. struct if_stack {
  539.   struct if_stack *next;    /* for chaining to the next stack frame */
  540.   char *fname;        /* copied from input when frame is made */
  541.   int lineno;            /* similarly */
  542.   int if_succeeded;        /* true if a leg of this if-group
  543.                     has been passed through rescan */
  544.   enum node_type type;        /* type of last directive seen in this group */
  545. };
  546. typedef struct if_stack IF_STACK_FRAME;
  547. IF_STACK_FRAME *if_stack = NULL;
  548.  
  549. /* Buffer of -M output.  */
  550.  
  551. char *deps_buffer;
  552.  
  553. /* Number of bytes allocated in above.  */
  554. int deps_allocated_size;
  555.  
  556. /* Number of bytes used.  */
  557. int deps_size;
  558.  
  559. /* Number of bytes since the last newline.  */
  560. int deps_column;
  561.  
  562. /* Nonzero means -I- has been seen,
  563.    so don't look for #include "foo" the source-file directory.  */
  564. int ignore_srcdir;
  565.  
  566. /* Handler for SIGPIPE.  */
  567.  
  568. static void
  569. pipe_closed ()
  570. {
  571.   fatal ("output pipe has been closed");
  572. }
  573.  
  574. int
  575. main (argc, argv)
  576.      int argc;
  577.      char **argv;
  578. {
  579.   int st_mode;
  580.   long st_size;
  581.   char *in_fname, *out_fname;
  582.   int f, i;
  583.   FILE_BUF *fp;
  584.   char **pend_files = (char **) xmalloc (argc * sizeof (char *));
  585.   char **pend_defs = (char **) xmalloc (argc * sizeof (char *));
  586.   char **pend_undefs = (char **) xmalloc (argc * sizeof (char *));
  587.   int inhibit_predefs = 0;
  588.   int no_standard_includes = 0;
  589.   char *machine = NULL;
  590.  
  591.   /* Non-0 means don't output the preprocessed program.  */
  592.   int inhibit_output = 0;
  593.  
  594.   /* Stream on which to print the dependency information.  */
  595.   FILE *deps_stream = 0;
  596.   /* Target-name to write with the dependency information.  */
  597.   char *deps_target = 0;
  598.  
  599. #ifdef RLIMIT_STACK
  600.   /* Get rid of any avoidable limit on stack size.  */
  601.   {
  602.     struct rlimit rlim;
  603.  
  604.     /* Set the stack limit huge so that alloca (particularly stringtab
  605.      * in dbxread.c) does not fail. */
  606.     getrlimit (RLIMIT_STACK, &rlim);
  607.     rlim.rlim_cur = rlim.rlim_max;
  608.     setrlimit (RLIMIT_STACK, &rlim);
  609.   }
  610. #endif /* RLIMIT_STACK defined */
  611.  
  612.   progname = argv[0];
  613. #ifdef VMS
  614.   {
  615.     /* Remove directories from PROGNAME.  */
  616.     char *s;
  617.     extern char *rindex ();
  618.  
  619.     progname = savestring (argv[0]);
  620.  
  621.     if (!(s = rindex (progname, ']')))
  622.       s = rindex (progname, ':');
  623.     if (s)
  624.       strcpy (progname, s+1);
  625.     if (s = rindex (progname, '.'))
  626.       *s = '\0';
  627.   }
  628. #endif
  629.  
  630.   in_fname = NULL;
  631.   out_fname = NULL;
  632.  
  633.   /* Initialize is_idchar to allow $.  */
  634.   dollars_in_ident = 1;
  635.   initialize_char_syntax ();
  636.   dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
  637.  
  638.   no_line_commands = 0;
  639.   no_trigraphs = 1;
  640.   dump_macros = 0;
  641.   no_output = 0;
  642.   cplusplus = 0;
  643. #ifdef CPLUSPLUS
  644.   cplusplus = 1;
  645. #endif
  646.  
  647.   signal (SIGPIPE, pipe_closed);
  648.  
  649. #ifndef VMS
  650.   max_include_len
  651.     = max (max (sizeof (GCC_INCLUDE_DIR),
  652.         sizeof (GPLUSPLUS_INCLUDE_DIR)),
  653.        sizeof ("/usr/include/CC"));
  654. #else /* VMS */
  655.   max_include_len
  656.     = sizeof("SYS$SYSROOT:[SYSLIB.]");
  657. #endif /* VMS */
  658.  
  659.   bzero (pend_files, argc * sizeof (char *));
  660.   bzero (pend_defs, argc * sizeof (char *));
  661.   bzero (pend_undefs, argc * sizeof (char *));
  662.  
  663.   /* Process switches and find input file name.  */
  664.  
  665.   for (i = 1; i < argc; i++) {
  666.     if (argv[i][0] != '-') {
  667.       if (out_fname != NULL)
  668.     fatal ("Usage: %s [switches] input output", argv[0]);
  669.       else if (in_fname != NULL)
  670.     out_fname = argv[i];
  671.       else
  672.     in_fname = argv[i];
  673.     } else {
  674.       switch (argv[i][1]) {
  675.  
  676.       case 'i':
  677.     if (argv[i][2] != 0)
  678.       pend_files[i] = argv[i] + 2;
  679.     else if (i + 1 == argc)
  680.       fatal ("Filename missing after -i option");
  681.     else
  682.       pend_files[i] = argv[i+1], i++;
  683.     break;
  684.  
  685.       case 'o':
  686.     if (out_fname != NULL)
  687.       fatal ("Output filename specified twice");
  688.     if (i + 1 == argc)
  689.       fatal ("Filename missing after -o option");
  690.     out_fname = argv[++i];
  691.     if (!strcmp (out_fname, "-"))
  692.       out_fname = "";
  693.     break;
  694.  
  695.       case 'p':
  696.     pedantic = 1;
  697.     break;
  698.  
  699.       case 't':
  700.     if (!strcmp (argv[i], "-traditional")) {
  701.       traditional = 1;
  702.       dollars_in_ident = 1;
  703.     } else if (!strcmp (argv[i], "-trigraphs")) {
  704.       no_trigraphs = 0;
  705.     }
  706.     break;
  707.  
  708.       case '+':
  709.     cplusplus = 1;
  710.     break;
  711.  
  712.       case 'W':
  713.     if (!strcmp (argv[i], "-Wtrigraphs")) {
  714.       warn_trigraphs = 1;
  715.     }
  716.     if (!strcmp (argv[i], "-Wcomments"))
  717.       warn_comments = 1;
  718.     if (!strcmp (argv[i], "-Wcomment"))
  719.       warn_comments = 1;
  720.     if (!strcmp (argv[i], "-Wall")) {
  721.       warn_trigraphs = 1;
  722.       warn_comments = 1;
  723.     }
  724.     break;
  725.  
  726.       case 'M':
  727.     if (!strcmp (argv[i], "-M"))
  728.       print_deps = 2;
  729.     else if (!strcmp (argv[i], "-MM"))
  730.       print_deps = 1;
  731.     inhibit_output = 1;
  732.     break;
  733.  
  734.       case 'd':
  735.     dump_macros = 1;
  736.     no_output = 1;
  737.     break;
  738.  
  739.       case 'v':
  740.     fprintf (stderr, "GNU CPP version %s\n", version_string);
  741.     break;
  742.  
  743.       case 'D':
  744.     {
  745.       char *p, *p1;
  746.  
  747.       if (argv[i][2] != 0)
  748.         p = argv[i] + 2;
  749.       else if (i + 1 == argc)
  750.         fatal ("Macro name missing after -D option");
  751.       else
  752.         p = argv[++i];
  753.  
  754.       if ((p1 = (char *) index (p, '=')) != NULL)
  755.         *p1 = ' ';
  756.       pend_defs[i] = p;
  757.     }
  758.     break;
  759.  
  760.       case 'U':        /* JF #undef something */
  761.     if (argv[i][2] != 0)
  762.       pend_undefs[i] = argv[i] + 2;
  763.     else if (i + 1 == argc)
  764.       fatal ("Macro name missing after -U option");
  765.     else
  766.       pend_undefs[i] = argv[i+1], i++;
  767.     break;
  768.  
  769.       case 'C':
  770.     put_out_comments = 1;
  771.     break;
  772.  
  773.       case 'E':            /* -E comes from cc -E; ignore it.  */
  774.     break;
  775.  
  776.       case 'P':
  777.     no_line_commands = 1;
  778.     break;
  779.  
  780.       case '$':            /* Don't include $ in identifiers.  */
  781.     dollars_in_ident = 0;
  782.     break;
  783.  
  784.       case 'I':            /* Add directory to path for includes.  */
  785.     {
  786.       struct file_name_list *dirtmp;
  787.  
  788.       if (! ignore_srcdir && !strcmp (argv[i] + 2, "-"))
  789.         ignore_srcdir = 1;
  790.       else {
  791.         dirtmp = (struct file_name_list *)
  792.           xmalloc (sizeof (struct file_name_list));
  793.         dirtmp->next = 0;        /* New one goes on the end */
  794.         if (include == 0)
  795.           include = dirtmp;
  796.         else
  797.           last_include->next = dirtmp;
  798.         last_include = dirtmp;    /* Tail follows the last one */
  799.         if (argv[i][2] != 0)
  800.           dirtmp->fname = argv[i] + 2;
  801.         else if (i + 1 == argc)
  802.           fatal ("Directory name missing after -I option");
  803.         else
  804.           dirtmp->fname = argv[++i];
  805.         if (strlen (dirtmp->fname) > max_include_len)
  806.           max_include_len = strlen (dirtmp->fname);
  807.         if (ignore_srcdir && first_bracket_include == 0)
  808.           first_bracket_include = dirtmp;
  809.         }
  810.     }
  811.     break;
  812.  
  813.       case 'n':
  814.     /* -nostdinc causes no default include directories.
  815.        You must specify all include-file directories with -I.  */
  816.     no_standard_includes = 1;
  817.     break;
  818.  
  819.       case 'u':
  820.     /* Sun compiler passes undocumented switch "-undef".
  821.        Let's assume it means to inhibit the predefined symbols.  */
  822.     inhibit_predefs = 1;
  823.     break;
  824.  
  825.       case '\0': /* JF handle '-' as file name meaning stdin or stdout */
  826.     if (in_fname == NULL) {
  827.       in_fname = "";
  828.       break;
  829.     } else if (out_fname == NULL) {
  830.       out_fname = "";
  831.       break;
  832.     }    /* else fall through into error */
  833.  
  834.       case 'm':
  835.     if (argv[i][2] != 0)
  836.       machine = argv[i] + 2;
  837.     else
  838.       machine = argv[i+1], i++;
  839.     break;
  840.  
  841.       default:
  842.     fatal ("Invalid option `%s'", argv[i]);
  843.       }
  844.     }
  845.   }
  846.  
  847. #ifdef sprite
  848.   /* Use machine information to complete the initialization of the
  849.   directory stack. */
  850.   if (machine == NULL) {
  851.     machine = getenv("MACHINE");
  852.   }
  853.   if (machine != NULL) {
  854.     include_defaults[0].fname = xmalloc((unsigned) (strlen(machine) + 30));
  855.     sprintf(include_defaults[0].fname, "/sprite/lib/include/%s.md", machine);
  856.     include_defaults[0].next = &include_defaults[1];
  857.     cplusplus_include_defaults[0].fname = include_defaults[0].fname;
  858.     cplusplus_include_defaults[0].next = &cplusplus_include_defaults[1];
  859.   } else {
  860.     include_defaults[0].fname = include_defaults[1].fname;
  861.     include_defaults[1].fname = NULL;
  862.     cplusplus_include_defaults[0].fname = cplusplus_include_defaults[1].fname;
  863.     cplusplus_include_defaults[1].fname = NULL;
  864.   }
  865.   for (i=0;i<sizeof(include_defaults)/sizeof(struct file_name_list);i++) {
  866.       if (include_defaults[i].fname == NULL) continue;
  867.       if (strlen(include_defaults[i].fname)>max_include_len) {
  868.       max_include_len = strlen(include_defaults[i].fname);
  869.       }
  870.   }
  871. #endif /* sprite */
  872.  
  873.   /* Now that dollars_in_ident is known, initialize is_idchar.  */
  874.   initialize_char_syntax ();
  875.  
  876.   /* Install __LINE__, etc.  Must follow initialize_char_syntax
  877.      and option processing.  */
  878.   initialize_builtins ();
  879.  
  880.   /* Do standard #defines that identify processor type.  */
  881.  
  882.   if (!inhibit_predefs) {
  883.     char *p = (char *) alloca (strlen (predefs) + 1);
  884.     strcpy (p, predefs);
  885.     while (*p) {
  886.       char *q;
  887.       if (p[0] != '-' || p[1] != 'D')
  888.     abort ();
  889.       q = &p[2];
  890.       while (*p && *p != ' ') p++;
  891.       if (*p != 0)
  892.     *p++= 0;
  893.       make_definition (q);
  894.     }
  895.   }
  896.  
  897.   /* Do defines specified with -D.  */
  898.   for (i = 1; i < argc; i++)
  899.     if (pend_defs[i])
  900.       make_definition (pend_defs[i]);
  901.  
  902.   /* Do undefines specified with -U.  */
  903.   for (i = 1; i < argc; i++)
  904.     if (pend_undefs[i])
  905.       make_undef (pend_undefs[i]);
  906.  
  907.   /* Unless -fnostdinc,
  908.      tack on the standard include file dirs to the specified list */
  909.   if (!no_standard_includes) {
  910.     if (include == 0)
  911.       include = (cplusplus ? cplusplus_include_defaults : include_defaults);
  912.     else
  913.       last_include->next
  914.     = (cplusplus ? cplusplus_include_defaults : include_defaults);
  915.     /* Make sure the list for #include <...> also has the standard dirs.  */
  916.     if (ignore_srcdir && first_bracket_include == 0)
  917.       first_bracket_include
  918.     = (cplusplus ? cplusplus_include_defaults : include_defaults);
  919.   }
  920.  
  921.   /* Initialize output buffer */
  922.  
  923.   outbuf.buf = (U_CHAR *) xmalloc (OUTBUF_SIZE);
  924.   outbuf.bufp = outbuf.buf;
  925.   outbuf.length = OUTBUF_SIZE;
  926.  
  927.   /* Scan the -i files before the main input.
  928.      Much like #including them, but with no_output set
  929.      so that only their macro definitions matter.  */
  930.  
  931.   no_output++;
  932.   for (i = 1; i < argc; i++)
  933.     if (pend_files[i]) {
  934.       int fd = open (pend_files[i], O_RDONLY, 0666);
  935.       if (fd < 0) {
  936.     perror_with_name (pend_files[i]);
  937.     return FATAL_EXIT_CODE;
  938.       }
  939.       finclude (fd, pend_files[i], &outbuf);
  940.     }
  941.   no_output--;
  942.  
  943.   /* Create an input stack level for the main input file
  944.      and copy the entire contents of the file into it.  */
  945.  
  946.   fp = &instack[++indepth];
  947.  
  948.   /* JF check for stdin */
  949.   if (in_fname == NULL || *in_fname == 0) {
  950.     in_fname = "";
  951.     f = 0;
  952.   } else if ((f = open (in_fname, O_RDONLY, 0666)) < 0)
  953.     goto perror;
  954.  
  955.   /* Either of two environment variables can specify output of deps.
  956.      Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
  957.      where OUTPUT_FILE is the file to write deps info to
  958.      and DEPS_TARGET is the target to mention in the deps.  */
  959.  
  960.   if (print_deps == 0
  961.       && (getenv ("SUNPRO_DEPENDENCIES") != 0
  962.       || getenv ("DEPENDENCIES_OUTPUT") != 0))
  963.     {
  964.       char *spec = getenv ("DEPENDENCIES_OUTPUT");
  965.       char *s;
  966.       char *output_file;
  967.  
  968.       if (spec == 0)
  969.     {
  970.       spec = getenv ("SUNPRO_DEPENDENCIES");
  971.       print_deps = 2;
  972.     }
  973.       else
  974.     print_deps = 1;
  975.  
  976.       s = spec;
  977.       /* Find the space before the DEPS_TARGET, if there is one.  */
  978.       /* Don't use `index'; that causes trouble on USG.  */
  979.       while (*s != 0 && *s != ' ') s++;
  980.       if (*s != 0)
  981.     {
  982.       deps_target = s + 1;
  983.       output_file = (char *) xmalloc (s - spec + 1);
  984.       bcopy (spec, output_file, s - spec);
  985.       output_file[s - spec] = 0;
  986.     }
  987.       else
  988.     {
  989.       deps_target = 0;
  990.       output_file = spec;
  991.     }
  992.       
  993.       deps_stream = fopen (output_file, "a");
  994.       if (deps_stream == 0)
  995.     pfatal_with_name (output_file);
  996.     }
  997.   /* If the -M option was used, output the deps to standard output.  */
  998.   else if (print_deps)
  999.     deps_stream = stdout;
  1000.  
  1001.   /* For -M, print the expected object file name
  1002.      as the target of this Make-rule.  */
  1003.   if (print_deps) {
  1004.     deps_allocated_size = 200;
  1005.     deps_buffer = (char *) xmalloc (deps_allocated_size);
  1006.     deps_buffer[0] = 0;
  1007.     deps_size = 0;
  1008.     deps_column = 0;
  1009.  
  1010.     if (deps_target) {
  1011.       deps_output (deps_target, 0);
  1012.       deps_output (":", 0);
  1013.     } else if (*in_fname == 0)
  1014.       deps_output ("-: ", 0);
  1015.     else {
  1016.       int len;
  1017.       char *p = in_fname;
  1018.       char *p1 = p;
  1019.       /* Discard all directory prefixes from P.  */
  1020.       while (*p1) {
  1021.     if (*p1 == '/')
  1022.       p = p1 + 1;
  1023.     p1++;
  1024.       }
  1025.       /* Output P, but remove known suffixes.  */
  1026.       len = strlen (p);
  1027.       if (p[len - 2] == '.' && p[len - 1] == 'c')
  1028.     deps_output (p, len - 2);
  1029.       else if (p[len - 3] == '.'
  1030.            && p[len - 2] == 'c'
  1031.            && p[len - 1] == 'c')
  1032.     deps_output (p, len - 3);
  1033.       else
  1034.     deps_output (p, 0);
  1035.       /* Supply our own suffix.  */
  1036.       deps_output (".o : ", 0);
  1037.       deps_output (in_fname, 0);
  1038.       deps_output (" ", 0);
  1039.     }
  1040.   }
  1041.  
  1042.   file_size_and_mode (f, &st_mode, &st_size);
  1043.   fp->fname = in_fname;
  1044.   fp->lineno = 1;
  1045.   /* JF all this is mine about reading pipes and ttys */
  1046.   if ((st_mode & S_IFMT) != S_IFREG) {
  1047.     /* Read input from a file that is not a normal disk file.
  1048.        We cannot preallocate a buffer with the correct size,
  1049.        so we must read in the file a piece at the time and make it bigger.  */
  1050.     int size;
  1051.     int bsize;
  1052.     int cnt;
  1053.     U_CHAR *bufp;
  1054.  
  1055.     bsize = 2000;
  1056.     size = 0;
  1057.     fp->buf = (U_CHAR *) xmalloc (bsize + 2);
  1058.     bufp = fp->buf;
  1059.     for (;;) {
  1060.       cnt = read (f, bufp, bsize - size);
  1061.       if (cnt < 0) goto perror;    /* error! */
  1062.       if (cnt == 0) break;    /* End of file */
  1063.       size += cnt;
  1064.       bufp += cnt;
  1065.       if (bsize == size) {    /* Buffer is full! */
  1066.         bsize *= 2;
  1067.         fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
  1068.     bufp = fp->buf + size;    /* May have moved */
  1069.       }
  1070.     }
  1071.     fp->length = size;
  1072.   } else {
  1073.     /* Read a file whose size we can determine in advance.
  1074.        For the sake of VMS, st_size is just an upper bound.  */
  1075.     long i;
  1076.     fp->length = 0;
  1077.     fp->buf = (U_CHAR *) xmalloc (st_size + 2);
  1078.  
  1079.     while (st_size > 0) {
  1080.       i = read (f, fp->buf + fp->length, st_size);
  1081.       if (i <= 0) {
  1082.         if (i == 0) break;
  1083.     goto perror;
  1084.       }
  1085.       fp->length += i;
  1086.       st_size -= i;
  1087.     }
  1088.   }
  1089.   fp->bufp = fp->buf;
  1090.   fp->if_stack = if_stack;
  1091.   
  1092.   /* Unless inhibited, convert trigraphs in the input.  */
  1093.  
  1094.   if (!no_trigraphs)
  1095.     trigraph_pcp (fp);
  1096.  
  1097.   /* Make sure data ends with a newline.  And put a null after it.  */
  1098.  
  1099.   if (fp->length > 0 && fp->buf[fp->length-1] != '\n')
  1100.     fp->buf[fp->length++] = '\n';
  1101.   fp->buf[fp->length] = '\0';
  1102.  
  1103.   /* Now that we know the input file is valid, open the output.  */
  1104.  
  1105.   if (!out_fname || !strcmp (out_fname, ""))
  1106.     out_fname = "stdout";
  1107.   else if (! freopen (out_fname, "w", stdout))
  1108.     pfatal_with_name (out_fname);
  1109.  
  1110.   output_line_command (fp, &outbuf, 0, same_file);
  1111.  
  1112.   /* Scan the input, processing macros and directives.  */
  1113.  
  1114.   rescan (&outbuf, 0);
  1115.  
  1116.   /* Now we have processed the entire input
  1117.      Write whichever kind of output has been requested.  */
  1118.  
  1119.  
  1120.   if (dump_macros)
  1121.     dump_all_macros ();
  1122.   else if (! inhibit_output && deps_stream != stdout) {
  1123.     if (write (fileno (stdout), outbuf.buf, outbuf.bufp - outbuf.buf) < 0)
  1124.       fatal ("I/O error on output");
  1125.   }
  1126.  
  1127.   if (print_deps) {
  1128.     fputs (deps_buffer, deps_stream);
  1129.     putc ('\n', deps_stream);
  1130.     if (deps_stream != stdout) {
  1131.       fclose (deps_stream);
  1132.       if (ferror (deps_stream))
  1133.     fatal ("I/O error on output");
  1134.     }
  1135.   }
  1136.  
  1137.   if (ferror (stdout))
  1138.     fatal ("I/O error on output");
  1139.  
  1140.   if (errors)
  1141.     exit (FATAL_EXIT_CODE);
  1142.   exit (SUCCESS_EXIT_CODE);
  1143.  
  1144.  perror:
  1145.   pfatal_with_name (in_fname);
  1146. }
  1147.  
  1148. /* Pre-C-Preprocessor to translate ANSI trigraph idiocy in BUF
  1149.    before main CCCP processing.  Name `pcp' is also in honor of the
  1150.    drugs the trigraph designers must have been on.
  1151.  
  1152.    Using an extra pass through the buffer takes a little extra time,
  1153.    but is infinitely less hairy than trying to handle ??/" inside
  1154.    strings, etc. everywhere, and also makes sure that trigraphs are
  1155.    only translated in the top level of processing. */
  1156.  
  1157. trigraph_pcp (buf)
  1158.      FILE_BUF *buf;
  1159. {
  1160.   register U_CHAR c, *fptr, *bptr, *sptr;
  1161.   int len;
  1162.  
  1163.   fptr = bptr = sptr = buf->buf;
  1164.   while ((sptr = (U_CHAR *) index (sptr, '?')) != NULL) {
  1165.     if (*++sptr != '?')
  1166.       continue;
  1167.     switch (*++sptr) {
  1168.       case '=':
  1169.       c = '#';
  1170.       break;
  1171.     case '(':
  1172.       c = '[';
  1173.       break;
  1174.     case '/':
  1175.       c = '\\';
  1176.       break;
  1177.     case ')':
  1178.       c = ']';
  1179.       break;
  1180.     case '\'':
  1181.       c = '^';
  1182.       break;
  1183.     case '<':
  1184.       c = '{';
  1185.       break;
  1186.     case '!':
  1187.       c = '|';
  1188.       break;
  1189.     case '>':
  1190.       c = '}';
  1191.       break;
  1192.     case '-':
  1193.       c  = '~';
  1194.       break;
  1195.     case '?':
  1196.       sptr--;
  1197.       continue;
  1198.     default:
  1199.       continue;
  1200.     }
  1201.     len = sptr - fptr - 2;
  1202.     if (bptr != fptr && len > 0)
  1203.       bcopy (fptr, bptr, len);    /* BSD doc says bcopy () works right
  1204.                    for overlapping strings.  In ANSI
  1205.                    C, this will be memmove (). */
  1206.     bptr += len;
  1207.     *bptr++ = c;
  1208.     fptr = ++sptr;
  1209.   }
  1210.   len = buf->length - (fptr - buf->buf);
  1211.   if (bptr != fptr && len > 0)
  1212.     bcopy (fptr, bptr, len);
  1213.   buf->length -= fptr - bptr;
  1214.   buf->buf[buf->length] = '\0';
  1215.   if (warn_trigraphs && fptr != bptr)
  1216.     warning ("%d trigraph(s) encountered", (fptr - bptr) / 2);
  1217. }
  1218.  
  1219. /* Move all backslash-newline pairs out of embarrassing places.
  1220.    Exchange all such pairs following BP
  1221.    with any potentially-embarrasing characters that follow them.
  1222.    Potentially-embarrassing characters are / and *
  1223.    (because a backslash-newline inside a comment delimiter
  1224.    would cause it not to be recognized).  */
  1225.  
  1226. newline_fix (bp)
  1227.      U_CHAR *bp;
  1228. {
  1229.   register U_CHAR *p = bp;
  1230.   register int count = 0;
  1231.  
  1232.   /* First count the backslash-newline pairs here.  */
  1233.  
  1234.   while (*p++ == '\\' && *p++ == '\n')
  1235.     count++;
  1236.  
  1237.   p = bp + count * 2;
  1238.  
  1239.   /* What follows the backslash-newlines is not embarrassing.  */
  1240.  
  1241.   if (count == 0 || (*p != '/' && *p != '*'))
  1242.     return;
  1243.  
  1244.   /* Copy all potentially embarrassing characters
  1245.      that follow the backslash-newline pairs
  1246.      down to where the pairs originally started.  */
  1247.  
  1248.   while (*p == '*' || *p == '/')
  1249.     *bp++ = *p++;
  1250.  
  1251.   /* Now write the same number of pairs after the embarrassing chars.  */
  1252.   while (count-- > 0) {
  1253.     *bp++ = '\\';
  1254.     *bp++ = '\n';
  1255.   }
  1256. }
  1257.  
  1258. /* Like newline_fix but for use within a directive-name.
  1259.    Move any backslash-newlines up past any following symbol constituents.  */
  1260.  
  1261. name_newline_fix (bp)
  1262.      U_CHAR *bp;
  1263. {
  1264.   register U_CHAR *p = bp;
  1265.   register int count = 0;
  1266.  
  1267.   /* First count the backslash-newline pairs here.  */
  1268.  
  1269.   while (*p++ == '\\' && *p++ == '\n')
  1270.     count++;
  1271.  
  1272.   p = bp + count * 2;
  1273.  
  1274.   /* What follows the backslash-newlines is not embarrassing.  */
  1275.  
  1276.   if (count == 0 || !is_idchar[*p])
  1277.     return;
  1278.  
  1279.   /* Copy all potentially embarrassing characters
  1280.      that follow the backslash-newline pairs
  1281.      down to where the pairs originally started.  */
  1282.  
  1283.   while (is_idchar[*p])
  1284.     *bp++ = *p++;
  1285.  
  1286.   /* Now write the same number of pairs after the embarrassing chars.  */
  1287.   while (count-- > 0) {
  1288.     *bp++ = '\\';
  1289.     *bp++ = '\n';
  1290.   }
  1291. }
  1292.  
  1293. /*
  1294.  * The main loop of the program.
  1295.  *
  1296.  * Read characters from the input stack, transferring them to the
  1297.  * output buffer OP.
  1298.  *
  1299.  * Macros are expanded and push levels on the input stack.
  1300.  * At the end of such a level it is popped off and we keep reading.
  1301.  * At the end of any other kind of level, we return.
  1302.  * #-directives are handled, except within macros.
  1303.  *
  1304.  * If OUTPUT_MARKS is nonzero, keep Newline markers found in the input
  1305.  * and insert them when appropriate.  This is set while scanning macro
  1306.  * arguments before substitution.  It is zero when scanning for final output.
  1307.  *   There are three types of Newline markers:
  1308.  *   * Newline -  follows a macro name that was not expanded
  1309.  *     because it appeared inside an expansion of the same macro.
  1310.  *     This marker prevents future expansion of that identifier.
  1311.  *     When the input is rescanned into the final output, these are deleted.
  1312.  *     These are also deleted by ## concatenation.
  1313.  *   * Newline Space (or Newline and any other whitespace character)
  1314.  *     stands for a place that tokens must be separated or whitespace
  1315.  *     is otherwise desirable, but where the ANSI standard specifies there
  1316.  *     is no whitespace.  This marker turns into a Space (or whichever other
  1317.  *     whitespace char appears in the marker) in the final output,
  1318.  *     but it turns into nothing in an argument that is stringified with #.
  1319.  *     Such stringified arguments are the only place where the ANSI standard
  1320.  *     specifies with precision that whitespace may not appear.
  1321.  *
  1322.  * During this function, IP->bufp is kept cached in IBP for speed of access.
  1323.  * Likewise, OP->bufp is kept in OBP.  Before calling a subroutine
  1324.  * IBP, IP and OBP must be copied back to memory.  IP and IBP are
  1325.  * copied back with the RECACHE macro.  OBP must be copied back from OP->bufp
  1326.  * explicitly, and before RECACHE, since RECACHE uses OBP.
  1327.  */
  1328.  
  1329. rescan (op, output_marks)
  1330.      FILE_BUF *op;
  1331.      int output_marks;
  1332. {
  1333.   /* Character being scanned in main loop.  */
  1334.   register U_CHAR c;
  1335.  
  1336.   /* Length of pending accumulated identifier.  */
  1337.   register int ident_length = 0;
  1338.  
  1339.   /* Hash code of pending accumulated identifier.  */
  1340.   register int hash = 0;
  1341.  
  1342.   /* Current input level (&instack[indepth]).  */
  1343.   FILE_BUF *ip;
  1344.  
  1345.   /* Pointer for scanning input.  */
  1346.   register U_CHAR *ibp;
  1347.  
  1348.   /* Pointer to end of input.  End of scan is controlled by LIMIT.  */
  1349.   register U_CHAR *limit;
  1350.  
  1351.   /* Pointer for storing output.  */
  1352.   register U_CHAR *obp;
  1353.  
  1354.   /* REDO_CHAR is nonzero if we are processing an identifier
  1355.      after backing up over the terminating character.
  1356.      Sometimes we process an identifier without backing up over
  1357.      the terminating character, if the terminating character
  1358.      is not special.  Backing up is done so that the terminating character
  1359.      will be dispatched on again once the identifier is dealt with.  */
  1360.   int redo_char = 0;
  1361.  
  1362.   /* 1 if within an identifier inside of which a concatenation
  1363.      marker (Newline -) has been seen.  */
  1364.   int concatenated = 0;
  1365.  
  1366.   /* While scanning a comment or a string constant,
  1367.      this records the line it started on, for error messages.  */
  1368.   int start_line;
  1369.  
  1370.   /* Record position of last `real' newline.  */
  1371.   U_CHAR *beg_of_line;
  1372.  
  1373. /* Pop the innermost input stack level, assuming it is a macro expansion.  */
  1374.  
  1375. #define POPMACRO \
  1376. do { ip->macro->type = T_MACRO;        \
  1377.      if (ip->free_ptr) free (ip->free_ptr);    \
  1378.      --indepth; } while (0)
  1379.  
  1380. /* Reload `rescan's local variables that describe the current
  1381.    level of the input stack.  */
  1382.  
  1383. #define RECACHE  \
  1384. do { ip = &instack[indepth];        \
  1385.      ibp = ip->bufp;            \
  1386.      limit = ip->buf + ip->length;    \
  1387.      op->bufp = obp;            \
  1388.      check_expand (op, limit - ibp);    \
  1389.      beg_of_line = 0;            \
  1390.      obp = op->bufp; } while (0)
  1391.  
  1392.   if (no_output && instack[indepth].fname != 0)
  1393.     skip_if_group (&instack[indepth], 1);
  1394.  
  1395.   obp = op->bufp;
  1396.   RECACHE;
  1397.   beg_of_line = ibp;
  1398.  
  1399.   /* Our caller must always put a null after the end of
  1400.      the input at each input stack level.  */
  1401.   if (*limit != 0)
  1402.     abort ();
  1403.  
  1404.   while (1) {
  1405.     c = *ibp++;
  1406.     *obp++ = c;
  1407.  
  1408.     switch (c) {
  1409.     case '\\':
  1410.       if (ibp >= limit)
  1411.     break;
  1412.       if (*ibp == '\n') {
  1413.     /* Always merge lines ending with backslash-newline,
  1414.        even in middle of identifier.  */
  1415.     ++ibp;
  1416.     ++ip->lineno;
  1417.     --obp;        /* remove backslash from obuf */
  1418.     break;
  1419.       }
  1420.       /* Otherwise, backslash suppresses specialness of following char,
  1421.      so copy it here to prevent the switch from seeing it.
  1422.      But first get any pending identifier processed.  */
  1423.       if (ident_length > 0)
  1424.     goto specialchar;
  1425.       *obp++ = *ibp++;
  1426.       break;
  1427.  
  1428.     case '#':
  1429.       /* If this is expanding a macro definition, don't recognize
  1430.      preprocessor directives.  */
  1431.       if (ip->macro != 0)
  1432.     goto randomchar;
  1433.       if (ident_length)
  1434.     goto specialchar;
  1435.  
  1436.       /* # keyword: a # must be first nonblank char on the line */
  1437.       if (beg_of_line == 0)
  1438.     goto randomchar;
  1439.       {
  1440.     U_CHAR *bp;
  1441.  
  1442.     /* Scan from start of line, skipping whitespace, comments
  1443.        and backslash-newlines, and see if we reach this #.
  1444.        If not, this # is not special.  */
  1445.     bp = beg_of_line;
  1446.     while (1) {
  1447.       if (is_hor_space[*bp])
  1448.         bp++;
  1449.       else if (*bp == '\\' && bp[1] == '\n')
  1450.         bp += 2;
  1451.       else if (*bp == '/' && bp[1] == '*') {
  1452.         bp += 2;
  1453.         while (!(*bp == '*' && bp[1] == '/'))
  1454.           bp++;
  1455.         bp += 2;
  1456.       }
  1457.       else if (cplusplus && *bp == '/' && bp[1] == '/') {
  1458.         bp += 2;
  1459.         while (*bp++ != '\n') ;
  1460.       }
  1461.       else break;
  1462.     }
  1463.     if (bp + 1 != ibp)
  1464.       goto randomchar;
  1465.       }
  1466.  
  1467.       /* This # can start a directive.  */
  1468.  
  1469.       --obp;        /* Don't copy the '#' */
  1470.  
  1471.       ip->bufp = ibp;
  1472.       op->bufp = obp;
  1473.       if (! handle_directive (ip, op)) {
  1474. #ifdef USE_C_ALLOCA
  1475.     alloca (0);
  1476. #endif
  1477.     /* Not a known directive: treat it as ordinary text.
  1478.        IP, OP, IBP, etc. have not been changed.  */
  1479.     if (no_output && instack[indepth].fname) {
  1480.       /* If not generating expanded output,
  1481.          what we do with ordinary text is skip it.
  1482.          Discard everything until next # directive.  */
  1483.       skip_if_group (&instack[indepth], 1);
  1484.       RECACHE;
  1485.       beg_of_line = ibp;
  1486.       break;
  1487.     }
  1488.     ++obp;        /* Copy the '#' after all */
  1489.     goto randomchar;
  1490.       }
  1491. #ifdef USE_C_ALLOCA
  1492.       alloca (0);
  1493. #endif
  1494.       /* A # directive has been successfully processed.  */
  1495.       /* If not generating expanded output, ignore everything until
  1496.      next # directive.  */
  1497.       if (no_output && instack[indepth].fname)
  1498.     skip_if_group (&instack[indepth], 1);
  1499.       obp = op->bufp;
  1500.       RECACHE;
  1501.       beg_of_line = ibp;
  1502.       break;
  1503.  
  1504.     case '\"':            /* skip quoted string */
  1505.     case '\'':
  1506.       /* A single quoted string is treated like a double -- some
  1507.      programs (e.g., troff) are perverse this way */
  1508.  
  1509.       if (ident_length)
  1510.     goto specialchar;
  1511.  
  1512.       start_line = ip->lineno;
  1513.  
  1514.       /* Skip ahead to a matching quote.  */
  1515.  
  1516.       while (1) {
  1517.     if (ibp >= limit) {
  1518.       if (traditional) {
  1519.         if (ip->macro != 0) {
  1520.           /* try harder: this string crosses a macro expansion boundary */
  1521.           POPMACRO;
  1522.           RECACHE;
  1523.           continue;
  1524.         }
  1525.       } else
  1526.         error_with_line (line_for_error (start_line),
  1527.                  "unterminated string or character constant");
  1528.       break;
  1529.     }
  1530.     *obp++ = *ibp;
  1531.     switch (*ibp++) {
  1532.     case '\n':
  1533.       ++ip->lineno;
  1534.       ++op->lineno;
  1535.       if (traditional)
  1536.         goto while2end;
  1537.       if (pedantic || c == '\'') {
  1538.         error_with_line (line_for_error (start_line),
  1539.                  "unterminated string or character constant");
  1540.         goto while2end;
  1541.       }
  1542.       break;
  1543.  
  1544.     case '\\':
  1545.       if (ibp >= limit)
  1546.         break;
  1547.       if (*ibp == '\n') {
  1548.         /* Backslash newline is replaced by nothing at all,
  1549.            but keep the line counts correct.  */
  1550.         --obp;
  1551.         ++ibp;
  1552.         ++ip->lineno;
  1553.       } else {
  1554.         /* ANSI stupidly requires that in \\ the second \
  1555.            is *not* prevented from combining with a newline.  */
  1556.         while (*ibp == '\\' && ibp[1] == '\n') {
  1557.           ibp += 2;
  1558.           ++ip->lineno;
  1559.         }
  1560.         *obp++ = *ibp++;
  1561.       }
  1562.       break;
  1563.  
  1564.     case '\"':
  1565.     case '\'':
  1566.       if (ibp[-1] == c)
  1567.         goto while2end;
  1568.       break;
  1569.     }
  1570.       }
  1571.     while2end:
  1572.       break;
  1573.  
  1574.     case '/':
  1575.       if (*ibp == '\\' && ibp[1] == '\n')
  1576.     newline_fix (ibp);
  1577.       if (cplusplus && *ibp == '/') {
  1578.     /* C++ style comment... */
  1579.     start_line = ip->lineno;
  1580.  
  1581.     --ibp;            /* Back over the slash */
  1582.     --obp;
  1583.  
  1584.     /* Comments are equivalent to spaces. */
  1585.     if (! put_out_comments)
  1586.       *obp++ = ' ';
  1587.     else {
  1588.       /* must fake up a comment here */
  1589.       *obp++ = '/';
  1590.       *obp++ = '/';
  1591.     }
  1592.     {
  1593.       U_CHAR *before_bp = ibp+2;
  1594.  
  1595.       while (ibp < limit) {
  1596.         if (*ibp++ == '\n') {
  1597.           ibp--;
  1598.           if (put_out_comments) {
  1599.         bcopy (before_bp, obp, ibp - before_bp);
  1600.         obp += ibp - before_bp;
  1601.           }
  1602.           break;
  1603.         }
  1604.       }
  1605.       break;
  1606.     }
  1607.       }
  1608.       if (*ibp != '*')
  1609.     goto randomchar;
  1610.       if (ip->macro != 0)
  1611.     goto randomchar;
  1612.       if (ident_length)
  1613.     goto specialchar;
  1614.  
  1615.       /* We have a comment.  Skip it, optionally copying it to output.  */
  1616.  
  1617.       start_line = ip->lineno;
  1618.  
  1619.       ++ibp;            /* Skip the star. */
  1620.  
  1621.       /* Comments are equivalent to spaces.
  1622.      Note that we already output the slash; we might not want it.
  1623.      For -traditional, a comment is equivalent to nothing.  */
  1624.       if (! put_out_comments) {
  1625.     if (traditional)
  1626.       obp--;
  1627.     else
  1628.       obp[-1] = ' ';
  1629.       }
  1630.       else
  1631.     *obp++ = '*';
  1632.  
  1633.       {
  1634.     U_CHAR *before_bp = ibp;
  1635.  
  1636.     while (ibp < limit) {
  1637.       switch (*ibp++) {
  1638.       case '/':
  1639.         if (warn_comments && ibp < limit && *ibp == '*')
  1640.           warning("`/*' within comment");
  1641.         break;
  1642.       case '*':
  1643.         if (*ibp == '\\' && ibp[1] == '\n')
  1644.           newline_fix (ibp);
  1645.         if (ibp >= limit || *ibp == '/')
  1646.           goto comment_end;
  1647.         break;
  1648.       case '\n':
  1649.         ++ip->lineno;
  1650.         /* Copy the newline into the output buffer, in order to
  1651.            avoid the pain of a #line every time a multiline comment
  1652.            is seen.  */
  1653.         if (!put_out_comments)
  1654.           *obp++ = '\n';
  1655.         ++op->lineno;
  1656.       }
  1657.     }
  1658.       comment_end:
  1659.  
  1660.     if (ibp >= limit)
  1661.       error_with_line (line_for_error (start_line),
  1662.                "unterminated comment");
  1663.     else {
  1664.       ibp++;
  1665.       if (put_out_comments) {
  1666.         bcopy (before_bp, obp, ibp - before_bp);
  1667.         obp += ibp - before_bp;
  1668.       }
  1669.     }
  1670.       }
  1671.       break;
  1672.  
  1673.     case '$':
  1674.       if (!dollars_in_ident)
  1675.     goto randomchar;
  1676.       goto letter;
  1677.  
  1678.     case '0': case '1': case '2': case '3': case '4':
  1679.     case '5': case '6': case '7': case '8': case '9':
  1680.       /* If digit is not part of identifier, it starts a number,
  1681.      which means that following letters are not an identifier.
  1682.      "0x5" does not refer to an identifier "x5".
  1683.      So copy all alphanumerics that follow without accumulating
  1684.      as an identifier.  Periods also, for sake of "3.e7".  */
  1685.  
  1686.       if (ident_length == 0) {
  1687.     while (ibp < limit) {
  1688.       c = *ibp++;
  1689.       if (!isalnum (c) && c != '.' && c != '_') {
  1690.         --ibp;
  1691.         break;
  1692.       }
  1693.       *obp++ = c;
  1694.       /* A sign can be part of a preprocessing number
  1695.          if it follows an e.  */
  1696.       if (c == 'e' || c == 'E') {
  1697.         if (ibp < limit && (*ibp == '+' || *ibp == '-'))
  1698.           *obp++ = *ibp++;
  1699.       }
  1700.     }
  1701.     break;
  1702.       }
  1703.       /* fall through */
  1704.  
  1705.     case '_':
  1706.     case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
  1707.     case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
  1708.     case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
  1709.     case 's': case 't': case 'u': case 'v': case 'w': case 'x':
  1710.     case 'y': case 'z':
  1711.     case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
  1712.     case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
  1713.     case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
  1714.     case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
  1715.     case 'Y': case 'Z':
  1716.     letter:
  1717.       ident_length++;
  1718.       /* Compute step of hash function, to avoid a proc call on every token */
  1719.       hash = HASHSTEP (hash, c);
  1720.       break;
  1721.  
  1722.     case '\n':
  1723.       /* If reprocessing a macro expansion, newline is a special marker.  */
  1724.       if (ip->macro != 0) {
  1725.     /* Newline White is a "funny space" to separate tokens that are
  1726.        supposed to be separate but without space between.
  1727.        Here White means any horizontal whitespace character.
  1728.        Newline - marks a recursive macro use that is not
  1729.        supposed to be expandable.  */
  1730.  
  1731.     if (*ibp == '-') {
  1732.       /* Newline - inhibits expansion of preceding token.
  1733.          If expanding a macro arg, we keep the newline -.
  1734.          In final output, it is deleted.  */
  1735.       if (! concatenated) {
  1736.         ident_length = 0;
  1737.         hash = 0;
  1738.       }
  1739.       ibp++;
  1740.       if (!output_marks) {
  1741.         obp--;
  1742.       } else {
  1743.         /* If expanding a macro arg, keep the newline -.  */
  1744.         *obp++ = '-';
  1745.       }
  1746.     } else if (is_space[*ibp]) {
  1747.       /* Newline Space does not prevent expansion of preceding token
  1748.          so expand the preceding token and then come back.  */
  1749.       if (ident_length > 0)
  1750.         goto specialchar;
  1751.  
  1752.       /* If generating final output, newline space makes a space.  */
  1753.       if (!output_marks) {
  1754.         obp[-1] = *ibp++;
  1755.         /* And Newline Newline makes a newline, so count it.  */
  1756.         if (obp[-1] == '\n')
  1757.           op->lineno++;
  1758.       } else {
  1759.         /* If expanding a macro arg, keep the newline space.
  1760.            If the arg gets stringified, newline space makes nothing.  */
  1761.         *obp++ = *ibp++;
  1762.       }
  1763.     } else abort ();    /* Newline followed by something random?  */
  1764.     break;
  1765.       }
  1766.  
  1767.       /* If there is a pending identifier, handle it and come back here.  */
  1768.       if (ident_length > 0)
  1769.     goto specialchar;
  1770.  
  1771.       beg_of_line = ibp;
  1772.  
  1773.       /* Update the line counts and output a #line if necessary.  */
  1774.       ++ip->lineno;
  1775.       ++op->lineno;
  1776.       if (ip->lineno != op->lineno) {
  1777.     op->bufp = obp;
  1778.     output_line_command (ip, op, 1, same_file);
  1779.     check_expand (op, ip->length - (ip->bufp - ip->buf));
  1780.     obp = op->bufp;
  1781.       }
  1782.       break;
  1783.  
  1784.       /* Come here either after (1) a null character that is part of the input
  1785.      or (2) at the end of the input, because there is a null there.  */
  1786.     case 0:
  1787.       if (ibp <= limit)
  1788.     /* Our input really contains a null character.  */
  1789.     goto randomchar;
  1790.  
  1791.       /* At end of a macro-expansion level, pop it and read next level.  */
  1792.       if (ip->macro != 0) {
  1793.     obp--;
  1794.     ibp--;
  1795.     /* If traditional, and we have an identifier that ends here,
  1796.        process it now, so we get the right error for recursion.  */
  1797.     if (traditional && ident_length
  1798.         && ! is_idchar[*instack[indepth - 1].bufp]) {
  1799.       redo_char = 1;
  1800.       goto randomchar;
  1801.     }
  1802.     POPMACRO;
  1803.     RECACHE;
  1804.     break;
  1805.       }
  1806.  
  1807.       /* If we don't have a pending identifier,
  1808.      return at end of input.  */
  1809.       if (ident_length == 0) {
  1810.     obp--;
  1811.     ibp--;
  1812.     op->bufp = obp;
  1813.     ip->bufp = ibp;
  1814.     goto ending;
  1815.       }
  1816.  
  1817.       /* If we do have a pending identifier, just consider this null
  1818.      a special character and arrange to dispatch on it again.
  1819.      The second time, IDENT_LENGTH will be zero so we will return.  */
  1820.  
  1821.       /* Fall through */
  1822.  
  1823. specialchar:
  1824.  
  1825.       /* Handle the case of a character such as /, ', " or null
  1826.      seen following an identifier.  Back over it so that
  1827.      after the identifier is processed the special char
  1828.      will be dispatched on again.  */
  1829.  
  1830.       ibp--;
  1831.       obp--;
  1832.       redo_char = 1;
  1833.  
  1834.     default:
  1835.  
  1836. randomchar:
  1837.  
  1838.       if (ident_length > 0) {
  1839.     register HASHNODE *hp;
  1840.  
  1841.     /* We have just seen an identifier end.  If it's a macro, expand it.
  1842.  
  1843.        IDENT_LENGTH is the length of the identifier
  1844.        and HASH is its hash code.
  1845.  
  1846.        The identifier has already been copied to the output,
  1847.        so if it is a macro we must remove it.
  1848.  
  1849.        If REDO_CHAR is 0, the char that terminated the identifier
  1850.        has been skipped in the output and the input.
  1851.        OBP-IDENT_LENGTH-1 points to the identifier.
  1852.        If the identifier is a macro, we must back over the terminator.
  1853.  
  1854.        If REDO_CHAR is 1, the terminating char has already been
  1855.        backed over.  OBP-IDENT_LENGTH points to the identifier.  */
  1856.  
  1857.     for (hp = hashtab[MAKE_POS (hash) % HASHSIZE]; hp != NULL;
  1858.          hp = hp->next) {
  1859.  
  1860.       if (hp->length == ident_length) {
  1861.         U_CHAR *obufp_before_macroname;
  1862.         int op_lineno_before_macroname;
  1863.         register int i = ident_length;
  1864.         register U_CHAR *p = hp->name;
  1865.         register U_CHAR *q = obp - i;
  1866.         int disabled;
  1867.  
  1868.         if (! redo_char)
  1869.           q--;
  1870.  
  1871.         do {        /* All this to avoid a strncmp () */
  1872.           if (*p++ != *q++)
  1873.         goto hashcollision;
  1874.         } while (--i);
  1875.  
  1876.         /* We found a use of a macro name.
  1877.            see if the context shows it is a macro call.  */
  1878.  
  1879.         /* Back up over terminating character if not already done.  */
  1880.         if (! redo_char) {
  1881.           ibp--;
  1882.           obp--;
  1883.         }
  1884.  
  1885.         obufp_before_macroname = obp - ident_length;
  1886.         op_lineno_before_macroname = op->lineno;
  1887.  
  1888.         /* Record whether the macro is disabled.  */
  1889.         disabled = hp->type == T_DISABLED;
  1890.  
  1891.         /* This looks like a macro ref, but if the macro was disabled,
  1892.            just copy its name and put in a marker if requested.  */
  1893.  
  1894.         if (disabled) {
  1895. #if 0
  1896.           /* This error check caught useful cases such as
  1897.          #define foo(x,y) bar(x(y,0), y)
  1898.          foo(foo, baz)  */
  1899.           if (traditional)
  1900.         error ("recursive use of macro `%s'", hp->name);
  1901. #endif
  1902.  
  1903.           if (output_marks) {
  1904.         check_expand (op, limit - ibp + 2);
  1905.         *obp++ = '\n';
  1906.         *obp++ = '-';
  1907.           }
  1908.           break;
  1909.         }
  1910.  
  1911.         /* If macro wants an arglist, verify that a '(' follows.
  1912.            first skip all whitespace, copying it to the output
  1913.            after the macro name.  Then, if there is no '(',
  1914.            decide this is not a macro call and leave things that way.  */
  1915.         if ((hp->type == T_MACRO || hp->type == T_DISABLED)
  1916.         && hp->value.defn->nargs >= 0)
  1917.           {
  1918.         while (1) {
  1919.           /* Scan forward over whitespace, copying it to the output.  */
  1920.           if (ibp == limit && ip->macro != 0) {
  1921.             POPMACRO;
  1922.             RECACHE;
  1923.           }
  1924.           /* A comment: copy it to the output unchanged.  */
  1925.           else if (*ibp == '/' && ibp+1 != limit && ibp[1] == '*') {
  1926.             *obp++ = '/';
  1927.             *obp++ = '*';
  1928.             ibp += 2;
  1929.             while (ibp + 1 != limit
  1930.                && !(ibp[0] == '*' && ibp[1] == '/')) {
  1931.               /* We need not worry about newline-marks,
  1932.              since they are never found in comments.  */
  1933.               if (*ibp == '\n') {
  1934.             /* Newline in a file.  Count it.  */
  1935.             ++ip->lineno;
  1936.             ++op->lineno;
  1937.               }
  1938.               *obp++ = *ibp++;
  1939.             }
  1940.             ibp += 2;
  1941.             *obp++ = '*';
  1942.             *obp++ = '/';
  1943.           }
  1944.           else if (is_space[*ibp]) {
  1945.             *obp++ = *ibp++;
  1946.             if (ibp[-1] == '\n') {
  1947.               if (ip->macro == 0) {
  1948.             /* Newline in a file.  Count it.  */
  1949.             ++ip->lineno;
  1950.             ++op->lineno;
  1951.               } else if (!output_marks) {
  1952.             /* A newline mark, and we don't want marks
  1953.                in the output.  If it is newline-hyphen,
  1954.                discard it entirely.  Otherwise, it is
  1955.                newline-whitechar, so keep the whitechar.  */
  1956.             obp--;
  1957.             if (*ibp == '-')
  1958.               ibp++;
  1959.             else {
  1960.               if (*ibp == '\n')
  1961.                 ++op->lineno;
  1962.               *obp++ = *ibp++;
  1963.             }
  1964.               } else {
  1965.             /* A newline mark; copy both chars to the output.  */
  1966.             *obp++ = *ibp++;
  1967.               }
  1968.             }
  1969.           }
  1970.           else break;
  1971.         }
  1972.         if (*ibp != '(')
  1973.           break;
  1974.           }
  1975.  
  1976.         /* This is now known to be a macro call.
  1977.            Discard the macro name from the output,
  1978.            along with any following whitespace just copied.  */
  1979.         obp = obufp_before_macroname;
  1980.         op->lineno = op_lineno_before_macroname;
  1981.  
  1982.         /* Expand the macro, reading arguments as needed,
  1983.            and push the expansion on the input stack.  */
  1984.         ip->bufp = ibp;
  1985.         op->bufp = obp;
  1986.         macroexpand (hp, op);
  1987.  
  1988.         /* Reexamine input stack, since macroexpand has pushed
  1989.            a new level on it.  */
  1990.         obp = op->bufp;
  1991.         RECACHE;
  1992.         break;
  1993.       }
  1994. hashcollision:
  1995.            ;
  1996.     }            /* End hash-table-search loop */
  1997.     ident_length = hash = 0; /* Stop collecting identifier */
  1998.     redo_char = 0;
  1999.     concatenated = 0;
  2000.       }                /* End if (ident_length > 0) */
  2001.     }                /* End switch */
  2002.   }                /* End per-char loop */
  2003.  
  2004.   /* Come here to return -- but first give an error message
  2005.      if there was an unterminated successful conditional.  */
  2006.  ending:
  2007.   if (if_stack != ip->if_stack) {
  2008.     char *str;
  2009.     switch (if_stack->type) {
  2010.     case T_IF:
  2011.       str = "if";
  2012.       break;
  2013.     case T_IFDEF:
  2014.       str = "ifdef";
  2015.       break;
  2016.     case T_IFNDEF:
  2017.       str = "ifndef";
  2018.       break;
  2019.     case T_ELSE:
  2020.       str = "else";
  2021.       break;
  2022.     case T_ELIF:
  2023.       str = "elif";
  2024.       break;
  2025.     }
  2026.     error_with_line (line_for_error (if_stack->lineno),
  2027.              "unterminated #%s conditional", str);
  2028.   }
  2029.   if_stack = ip->if_stack;
  2030. }
  2031.  
  2032. /*
  2033.  * Rescan a string into a temporary buffer and return the result
  2034.  * as a FILE_BUF.  Note this function returns a struct, not a pointer.
  2035.  *
  2036.  * OUTPUT_MARKS nonzero means keep Newline markers found in the input
  2037.  * and insert such markers when appropriate.  See `rescan' for details.
  2038.  * OUTPUT_MARKS is 1 for macroexpanding a macro argument separately
  2039.  * before substitution; it is 0 for other uses.
  2040.  */
  2041. FILE_BUF
  2042. expand_to_temp_buffer (buf, limit, output_marks)
  2043.      U_CHAR *buf, *limit;
  2044.      int output_marks;
  2045. {
  2046.   register FILE_BUF *ip;
  2047.   FILE_BUF obuf;
  2048.   int length = limit - buf;
  2049.   U_CHAR *buf1;
  2050.   int odepth = indepth;
  2051.  
  2052.   if (length < 0)
  2053.     abort ();
  2054.  
  2055.   /* Set up the input on the input stack.  */
  2056.  
  2057.   buf1 = (U_CHAR *) alloca (length + 1);
  2058.   {
  2059.     register U_CHAR *p1 = buf;
  2060.     register U_CHAR *p2 = buf1;
  2061.  
  2062.     while (p1 != limit)
  2063.       *p2++ = *p1++;
  2064.   }
  2065.   buf1[length] = 0;
  2066.  
  2067.   /* Set up to receive the output.  */
  2068.  
  2069.   obuf.length = length * 2 + 100; /* Usually enough.  Why be stingy?  */
  2070.   obuf.bufp = obuf.buf = (U_CHAR *) xmalloc (obuf.length);
  2071.   obuf.fname = 0;
  2072.   obuf.macro = 0;
  2073.   obuf.free_ptr = 0;
  2074.  
  2075.   CHECK_DEPTH ({return obuf;});
  2076.  
  2077.   ++indepth;
  2078.  
  2079.   ip = &instack[indepth];
  2080.   ip->fname = 0;
  2081.   ip->macro = 0;
  2082.   ip->free_ptr = 0;
  2083.   ip->length = length;
  2084.   ip->buf = ip->bufp = buf1;
  2085.   ip->if_stack = if_stack;
  2086.  
  2087.   ip->lineno = obuf.lineno = 1;
  2088.  
  2089.   /* Scan the input, create the output.  */
  2090.  
  2091.   rescan (&obuf, output_marks);
  2092.  
  2093.   /* Pop input stack to original state.  */
  2094.   --indepth;
  2095.  
  2096.   if (indepth != odepth)
  2097.     abort ();
  2098.  
  2099.   /* Record the output.  */
  2100.   obuf.length = obuf.bufp - obuf.buf;
  2101.  
  2102.   return obuf;
  2103. }
  2104.  
  2105. /*
  2106.  * Process a # directive.  Expects IP->bufp to point to the '#', as in
  2107.  * `#define foo bar'.  Passes to the command handler
  2108.  * (do_define, do_include, etc.): the addresses of the 1st and
  2109.  * last chars of the command (starting immediately after the #
  2110.  * keyword), plus op and the keyword table pointer.  If the command
  2111.  * contains comments it is copied into a temporary buffer sans comments
  2112.  * and the temporary buffer is passed to the command handler instead.
  2113.  * Likewise for backslash-newlines.
  2114.  *
  2115.  * Returns nonzero if this was a known # directive.
  2116.  * Otherwise, returns zero, without advancing the input pointer.
  2117.  */
  2118.  
  2119. int
  2120. handle_directive (ip, op)
  2121.      FILE_BUF *ip, *op;
  2122. {
  2123.   register U_CHAR *bp, *cp;
  2124.   register struct directive *kt;
  2125.   register int ident_length;
  2126.   U_CHAR *resume_p;
  2127.  
  2128.   /* Nonzero means we must copy the entire command
  2129.      to get rid of comments or backslash-newlines.  */
  2130.   int copy_command = 0;
  2131.  
  2132.   U_CHAR *ident, *after_ident;
  2133.  
  2134.   bp = ip->bufp;
  2135.   /* Skip whitespace and \-newline.  */
  2136.   while (1) {
  2137.     if (is_hor_space[*bp])
  2138.       bp++;
  2139.     else if (*bp == '/' && bp[1] == '*') {
  2140.       ip->bufp = bp;
  2141.       skip_to_end_of_comment (ip, &ip->lineno);
  2142.       bp = ip->bufp;
  2143.     } else if (*bp == '\\' && bp[1] == '\n') {
  2144.       bp += 2; ip->lineno++;
  2145.     } else break;
  2146.   }
  2147.  
  2148.   /* Now find end of directive name.
  2149.      If we encounter a backslash-newline, exchange it with any following
  2150.      symbol-constituents so that we end up with a contiguous name.  */
  2151.  
  2152.   cp = bp;
  2153.   while (1) {
  2154.     if (is_idchar[*cp])
  2155.       cp++;
  2156.     else {
  2157.       if (*cp == '\\' && cp[1] == '\n')
  2158.     name_newline_fix (cp);
  2159.       if (is_idchar[*cp])
  2160.     cp++;
  2161.       else break;
  2162.     }
  2163.   }
  2164.   ident_length = cp - bp;
  2165.   ident = bp;
  2166.   after_ident = cp;
  2167.  
  2168.   /* A line of just `#' becomes blank.  */
  2169.  
  2170.   if (traditional && ident_length == 0 && *after_ident == '\n') {
  2171.     ip->bufp = after_ident;
  2172.     return 1;
  2173.   }
  2174.  
  2175.   /*
  2176.    * Decode the keyword and call the appropriate expansion
  2177.    * routine, after moving the input pointer up to the next line.
  2178.    */
  2179.   for (kt = directive_table; kt->length > 0; kt++) {
  2180.     if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length)) {
  2181.       register U_CHAR *buf;
  2182.       register U_CHAR *limit = ip->buf + ip->length;
  2183.       int unterminated = 0;
  2184.  
  2185.       /* Nonzero means do not delete comments within the directive.
  2186.      #define needs this when -traditional.  */
  2187.       int keep_comments = traditional && kt->traditional_comments;
  2188.  
  2189.       /* Find the end of this command (first newline not backslashed
  2190.      and not in a string or comment).
  2191.      Set COPY_COMMAND if the command must be copied
  2192.      (it contains a backslash-newline or a comment).  */
  2193.  
  2194.       buf = bp = after_ident;
  2195.       while (bp < limit) {
  2196.     register U_CHAR c = *bp++;
  2197.     switch (c) {
  2198.     case '\\':
  2199.       if (bp < limit) {
  2200.         if (*bp == '\n') {
  2201.           ip->lineno++;
  2202.           copy_command = 1;
  2203.         }
  2204.         bp++;
  2205.       }
  2206.       break;
  2207.  
  2208.     case '\'':
  2209.     case '\"':
  2210.       bp = skip_quoted_string (bp - 1, limit, ip->lineno, &ip->lineno, ©_command, &unterminated);
  2211.       /* Don't bother calling the directive if we already got an error
  2212.          message due to unterminated string.  Skip everything and pretend
  2213.          we called the directive.  */
  2214.       if (unterminated) {
  2215.         if (traditional) {
  2216.           /* Traditional preprocessing permits unterminated strings.  */
  2217.           --bp;
  2218.           ip->bufp = bp;
  2219.           goto endloop1;
  2220.         }
  2221.         ip->bufp = bp;
  2222.         return 1;
  2223.       }
  2224.       break;
  2225.  
  2226.       /* <...> is special for #include.  */
  2227.     case '<':
  2228.       if (!kt->angle_brackets)
  2229.         break;
  2230.       while (*bp && *bp != '>') bp++;
  2231.       break;
  2232.  
  2233.     case '/':
  2234.       if (*bp == '\\' && bp[1] == '\n')
  2235.         newline_fix (bp);
  2236.       if (*bp == '*'
  2237.           || (cplusplus && *bp == '/')) {
  2238.         U_CHAR *obp = bp - 1;
  2239.         ip->bufp = bp + 1;
  2240.         skip_to_end_of_comment (ip, &ip->lineno);
  2241.         bp = ip->bufp;
  2242.         /* No need to copy the command because of a comment at the end;
  2243.            just don't include the comment in the directive.  */
  2244.         if (bp == limit || *bp == '\n') {
  2245.           bp = obp;
  2246.           goto endloop1;
  2247.         }
  2248.         /* Don't remove the comments if -traditional.  */
  2249.         if (! keep_comments)
  2250.           copy_command++;
  2251.       }
  2252.       break;
  2253.  
  2254.     case '\n':
  2255.       --bp;        /* Point to the newline */
  2256.       ip->bufp = bp;
  2257.       goto endloop1;
  2258.     }
  2259.       }
  2260.       ip->bufp = bp;
  2261.  
  2262.     endloop1:
  2263.       resume_p = ip->bufp;
  2264.       /* BP is the end of the directive.
  2265.      RESUME_P is the next interesting data after the directive.
  2266.      A comment may come between.  */
  2267.  
  2268.       if (copy_command) {
  2269.     register U_CHAR *xp = buf;
  2270.     /* Need to copy entire command into temp buffer before dispatching */
  2271.  
  2272.     cp = (U_CHAR *) alloca (bp - buf + 5); /* room for cmd plus
  2273.                           some slop */
  2274.     buf = cp;
  2275.  
  2276.     /* Copy to the new buffer, deleting comments
  2277.        and backslash-newlines (and whitespace surrounding the latter).  */
  2278.  
  2279.     while (xp < bp) {
  2280.       register U_CHAR c = *xp++;
  2281.       *cp++ = c;
  2282.  
  2283.       switch (c) {
  2284.       case '\n':
  2285.         break;
  2286.  
  2287.         /* <...> is special for #include.  */
  2288.       case '<':
  2289.         if (!kt->angle_brackets)
  2290.           break;
  2291.         while (xp < bp && c != '>') {
  2292.           c = *xp++;
  2293.           *cp++ = c;
  2294.         }
  2295.         break;
  2296.  
  2297.       case '\\':
  2298.         if (*xp == '\n') {
  2299.           xp++;
  2300.           cp--;
  2301.           if (cp != buf && is_space[cp[-1]]) {
  2302.         while (cp != buf && is_space[cp[-1]]) cp--;
  2303.         cp++;
  2304.         SKIP_WHITE_SPACE (xp);
  2305.           } else if (is_space[*xp]) {
  2306.         *cp++ = *xp++;
  2307.         SKIP_WHITE_SPACE (xp);
  2308.           }
  2309.         }
  2310.         break;
  2311.  
  2312.       case '\'':
  2313.       case '\"':
  2314.         if (!traditional) {
  2315.           register U_CHAR *bp1
  2316.         = skip_quoted_string (xp - 1, limit, ip->lineno, 0, 0, 0);
  2317.           while (xp != bp1)
  2318.         *cp++ = *xp++;
  2319.         }
  2320.         break;
  2321.  
  2322.       case '/':
  2323.         if (keep_comments)
  2324.           break;
  2325.         if (*xp == '*'
  2326.         || (cplusplus && *xp == '/')) {
  2327.           if (traditional)
  2328.         cp--;
  2329.           else
  2330.         cp[-1] = ' ';
  2331.           ip->bufp = xp + 1;
  2332.           skip_to_end_of_comment (ip, 0);
  2333.           xp = ip->bufp;
  2334.         }
  2335.       }
  2336.     }
  2337.  
  2338.     /* Null-terminate the copy.  */
  2339.  
  2340.     *cp = 0;
  2341.       }
  2342.       else
  2343.     cp = bp;
  2344.  
  2345.       ip->bufp = resume_p;
  2346.  
  2347.       /* Some directives should be written out for cc1 to process,
  2348.      just as if they were not defined.  */
  2349.  
  2350.       if (kt->pass_thru) {
  2351.         int len;
  2352.  
  2353.     /* Output directive name.  */
  2354.         check_expand (op, kt->length+1);
  2355.         *op->bufp++ = '#';
  2356.         bcopy (kt->name, op->bufp, kt->length);
  2357.         op->bufp += kt->length;
  2358.  
  2359.     /* Output arguments.  */
  2360.         len = (cp - buf);
  2361.         check_expand (op, len);
  2362.         bcopy (buf, op->bufp, len);
  2363.         op->bufp += len;
  2364.       }
  2365.  
  2366.       /* Call the appropriate command handler.  buf now points to
  2367.      either the appropriate place in the input buffer, or to
  2368.      the temp buffer if it was necessary to make one.  cp
  2369.      points to the first char after the contents of the (possibly
  2370.      copied) command, in either case. */
  2371.       (*kt->func) (buf, cp, op, kt);
  2372.       check_expand (op, ip->length - (ip->bufp - ip->buf));
  2373.  
  2374.       return 1;
  2375.     }
  2376.   }
  2377.  
  2378.   return 0;
  2379. }
  2380.  
  2381. static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  2382.                  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  2383.                 };
  2384.  
  2385. /*
  2386.  * expand things like __FILE__.  Place the expansion into the output
  2387.  * buffer *without* rescanning.
  2388.  */
  2389. special_symbol (hp, op)
  2390.      HASHNODE *hp;
  2391.      FILE_BUF *op;
  2392. {
  2393.   char *buf;
  2394.   long t;
  2395.   int i, len;
  2396.   int true_indepth;
  2397.   FILE_BUF *ip = NULL;
  2398.   static struct tm *timebuf = NULL;
  2399.   struct tm *localtime ();
  2400.  
  2401.   int paren = 0;        /* For special `defined' keyword */
  2402.  
  2403.   for (i = indepth; i >= 0; i--)
  2404.     if (instack[i].fname != NULL) {
  2405.       ip = &instack[i];
  2406.       break;
  2407.     }
  2408.   if (ip == NULL) {
  2409.     error ("cccp error: not in any file?!");
  2410.     return;            /* the show must go on */
  2411.   }
  2412.  
  2413.   switch (hp->type) {
  2414.   case T_FILE:
  2415.   case T_BASE_FILE:
  2416.     {
  2417.       char *string;
  2418.       if (hp->type == T_FILE)
  2419.     string = ip->fname;
  2420.       else
  2421.     string = instack[0].fname;
  2422.  
  2423.       if (string)
  2424.     {
  2425.       buf = (char *) alloca (3 + strlen (string));
  2426.       sprintf (buf, "\"%s\"", string);
  2427.     }
  2428.       else
  2429.     buf = "\"\"";
  2430.  
  2431.       break;
  2432.     }
  2433.  
  2434.   case T_INCLUDE_LEVEL:
  2435.     true_indepth = 0;
  2436.     for (i = indepth; i >= 0; i--)
  2437.       if (instack[i].fname != NULL)
  2438.         true_indepth++;
  2439.  
  2440.     buf = (char *) alloca (8);    /* Eigth bytes ought to be more than enough */
  2441.     sprintf (buf, "%d", true_indepth - 1);
  2442.     break;
  2443.  
  2444.   case T_VERSION:
  2445.     buf = (char *) alloca (3 + strlen (version_string));
  2446.     sprintf (buf, "\"%s\"", version_string);
  2447.     break;
  2448.  
  2449.   case T_CONST:
  2450.     buf = (char *) alloca (4 * sizeof (int));
  2451.     sprintf (buf, "%d", hp->value.ival);
  2452.     break;
  2453.  
  2454.   case T_SPECLINE:
  2455.     buf = (char *) alloca (10);
  2456.     sprintf (buf, "%d", ip->lineno);
  2457.     break;
  2458.  
  2459.   case T_DATE:
  2460.   case T_TIME:
  2461.     if (timebuf == NULL) {
  2462.       t = time (0);
  2463.       timebuf = localtime (&t);
  2464.     }
  2465.     buf = (char *) alloca (20);
  2466.     if (hp->type == T_DATE)
  2467.       sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
  2468.           timebuf->tm_mday, timebuf->tm_year + 1900);
  2469.     else
  2470.       sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
  2471.           timebuf->tm_sec);
  2472.     break;
  2473.  
  2474.   case T_SPEC_DEFINED:
  2475.     buf = " 0 ";        /* Assume symbol is not defined */
  2476.     ip = &instack[indepth];
  2477.     SKIP_WHITE_SPACE (ip->bufp);
  2478.     if (*ip->bufp == '(') {
  2479.       paren++;
  2480.       ip->bufp++;            /* Skip over the paren */
  2481.       SKIP_WHITE_SPACE (ip->bufp);
  2482.     }
  2483.  
  2484.     if (!is_idstart[*ip->bufp])
  2485.       goto oops;
  2486.     if (lookup (ip->bufp, -1, -1))
  2487.       buf = " 1 ";
  2488.     while (is_idchar[*ip->bufp])
  2489.       ++ip->bufp;
  2490.     SKIP_WHITE_SPACE (ip->bufp);
  2491.     if (paren) {
  2492.       if (*ip->bufp != ')')
  2493.     goto oops;
  2494.       ++ip->bufp;
  2495.     }
  2496.     break;
  2497.  
  2498. oops:
  2499.  
  2500.     error ("`defined' must be followed by ident or (ident)");
  2501.     break;
  2502.  
  2503.   default:
  2504.     error ("cccp error: invalid special hash type"); /* time for gdb */
  2505.     abort ();
  2506.   }
  2507.   len = strlen (buf);
  2508.   check_expand (op, len);
  2509.   bcopy (buf, op->bufp, len);
  2510.   op->bufp += len;
  2511.  
  2512.   return;
  2513. }
  2514.  
  2515.  
  2516. /* Routines to handle #directives */
  2517.  
  2518. /*
  2519.  * Process include file by reading it in and calling rescan.
  2520.  * Expects to see "fname" or <fname> on the input.
  2521.  */
  2522.  
  2523. do_include (buf, limit, op, keyword)
  2524.      U_CHAR *buf, *limit;
  2525.      FILE_BUF *op;
  2526.      struct directive *keyword;
  2527. {
  2528.   char *fname;        /* Dynamically allocated fname buffer */
  2529.   U_CHAR *fbeg, *fend;        /* Beginning and end of fname */
  2530.  
  2531.   struct file_name_list *stackp = include; /* Chain of dirs to search */
  2532.   struct file_name_list dsp[1];    /* First in chain, if #include "..." */
  2533.   int flen;
  2534.  
  2535.   int f;            /* file number */
  2536.  
  2537.   int retried = 0;        /* Have already tried macro
  2538.                    expanding the include line*/
  2539.   FILE_BUF trybuf;        /* It got expanded into here */
  2540.   int system_header_p = 0;    /* 0 for "...", 1 for <...> */
  2541.  
  2542.   f= -1;            /* JF we iz paranoid! */
  2543.  
  2544. get_filename:
  2545.  
  2546.   fbeg = buf;
  2547.   SKIP_WHITE_SPACE (fbeg);
  2548.   /* Discard trailing whitespace so we can easily see
  2549.      if we have parsed all the significant chars we were given.  */
  2550.   while (limit != fbeg && is_hor_space[limit[-1]]) limit--;
  2551.  
  2552.   switch (*fbeg++) {
  2553.   case '\"':
  2554.     fend = fbeg;
  2555.     while (fend != limit && *fend != '\"')
  2556.       fend++;
  2557.     if (*fend == '\"' && fend + 1 == limit) {
  2558.       FILE_BUF *fp;
  2559.  
  2560.       /* We have "filename".  Figure out directory this source
  2561.      file is coming from and put it on the front of the list. */
  2562.  
  2563.       /* If -I- was specified, don't search current dir, only spec'd ones. */
  2564.       if (ignore_srcdir) break;
  2565.  
  2566.       for (fp = &instack[indepth]; fp >= instack; fp--)
  2567.     {
  2568.       int n;
  2569.       char *ep,*nam;
  2570.       extern char *rindex ();
  2571.  
  2572.       if ((nam = fp->fname) != NULL) {
  2573.         /* Found a named file.  Figure out dir of the file,
  2574.            and put it in front of the search list.  */
  2575.         dsp[0].next = stackp;
  2576.         stackp = dsp;
  2577. #ifndef VMS
  2578.         ep = rindex (nam, '/');
  2579. #else                /* VMS */
  2580.         ep = rindex (nam, ']');
  2581.         if (ep == NULL) ep = rindex (nam, '>');
  2582.         if (ep == NULL) ep = rindex (nam, ':');
  2583.         if (ep != NULL) ep++;
  2584. #endif                /* VMS */
  2585.         if (ep != NULL) {
  2586.           n = ep - nam;
  2587.           dsp[0].fname = (char *) alloca (n + 1);
  2588.           strncpy (dsp[0].fname, nam, n);
  2589.           dsp[0].fname[n] = '\0';
  2590.           if (n > max_include_len) max_include_len = n;
  2591.         } else {
  2592.           dsp[0].fname = 0; /* Current directory */
  2593.         }
  2594.         break;
  2595.       }
  2596.     }
  2597.       break;
  2598.     }
  2599.     goto fail;
  2600.  
  2601.   case '<':
  2602.     fend = fbeg;
  2603.     while (fend != limit && *fend != '>') fend++;
  2604.     if (*fend == '>' && fend + 1 == limit) {
  2605.       system_header_p = 1;
  2606.       /* If -I-, start with the first -I dir after the -I-.  */
  2607.       if (first_bracket_include)
  2608.     stackp = first_bracket_include;
  2609.       break;
  2610.     }
  2611.     goto fail;
  2612.  
  2613.   default:
  2614.   fail:
  2615.     if (retried) {
  2616.       error ("#include expects \"fname\" or <fname>");
  2617.       return;
  2618.     } else {
  2619.       trybuf = expand_to_temp_buffer (buf, limit, 0);
  2620.       buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1);
  2621.       bcopy (trybuf.buf, buf, trybuf.bufp - trybuf.buf);
  2622.       limit = buf + (trybuf.bufp - trybuf.buf);
  2623.       free (trybuf.buf);
  2624.       retried++;
  2625.       goto get_filename;
  2626.     }
  2627.   }
  2628.  
  2629.   flen = fend - fbeg;
  2630.   fname = (char *) alloca (max_include_len + flen + 2);
  2631.   /* + 2 above for slash and terminating null.  */
  2632.  
  2633.   /* If specified file name is absolute, just open it.  */
  2634.  
  2635.   if (*fbeg == '/') {
  2636.     strncpy (fname, fbeg, flen);
  2637.     fname[flen] = 0;
  2638.     f = open (fname, O_RDONLY, 0666);
  2639.   } else {
  2640.     /* Search directory path, trying to open the file.
  2641.        Copy each filename tried into FNAME.  */
  2642.  
  2643.     for (; stackp; stackp = stackp->next) {
  2644.       if (stackp->fname) {
  2645.     if (strlen(stackp->fname) > max_include_len) {
  2646.         fprintf(stderr,"Error in cpc: \"%s\" unexpectedly long\n",
  2647.             stackp->fname);
  2648.         exit(-1);
  2649.     }
  2650.     strcpy (fname, stackp->fname);
  2651.     strcat (fname, "/");
  2652.     fname[strlen (fname) + flen] = 0;
  2653.       } else {
  2654.     fname[0] = 0;
  2655.       }
  2656.       strncat (fname, fbeg, flen);
  2657. #ifdef VMS
  2658.       /* Change this 1/2 Unix 1/2 VMS file specification into a
  2659.          full VMS file specification */
  2660.       if (stackp->fname && (stackp->fname[0] != 0)) {
  2661.     /* Fix up the filename */
  2662.     hack_vms_include_specification (fname);
  2663.       } else {
  2664.           /* This is a normal VMS filespec, so use it unchanged.  */
  2665.     strncpy (fname, fbeg, flen);
  2666.     fname[flen] = 0;
  2667.       }
  2668. #endif /* VMS */
  2669.       if ((f = open (fname, O_RDONLY, 0666)) >= 0)
  2670.     break;
  2671.     }
  2672.   }
  2673.  
  2674.   if (f < 0) {
  2675.     strncpy (fname, fbeg, flen);
  2676.     fname[flen] = 0;
  2677.     error_from_errno (fname);
  2678.  
  2679.     /* For -M, add this file to the dependencies.  */
  2680.     if (print_deps > (system_header_p || (system_include_depth > 0))) {
  2681.       if (system_header_p)
  2682.     warning ("nonexistent file <%.*s> omitted from dependency output",
  2683.          fend - fbeg, fbeg);
  2684.       else
  2685.     {
  2686.       deps_output (fbeg, fend - fbeg);
  2687.       deps_output (" ", 0);
  2688.     }
  2689.     }
  2690.   } else {
  2691.  
  2692.     /* Check to see if this include file is a once-only include file.
  2693.        If so, give up.  */
  2694.  
  2695.     struct file_name_list* ptr;
  2696.  
  2697.     for (ptr = dont_repeat_files; ptr; ptr = ptr->next) {
  2698.       if (!strcmp (ptr->fname, fname)) {
  2699.     close (f);
  2700.         return;                /* This file was once'd. */
  2701.       }
  2702.     }
  2703.  
  2704.     for (ptr = all_include_files; ptr; ptr = ptr->next) {
  2705.       if (!strcmp (ptr->fname, fname))
  2706.         break;                /* This file was included before. */
  2707.     }
  2708.  
  2709.     if (ptr == 0) {
  2710.       /* This is the first time for this file.  */
  2711.       /* Add it to list of files included.  */
  2712.  
  2713.       ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
  2714.       ptr->next = all_include_files;
  2715.       all_include_files = ptr;
  2716.       ptr->fname = savestring (fname);
  2717.  
  2718.       /* For -M, add this file to the dependencies.  */
  2719.       if (print_deps > (system_header_p || (system_include_depth > 0))) {
  2720.     deps_output (fname, strlen (fname));
  2721.     deps_output (" ", 0);
  2722.       }
  2723.     }   
  2724.  
  2725.     if (system_header_p)
  2726.       system_include_depth++;
  2727.  
  2728.     /* Actually process the file.  */
  2729.     finclude (f, fname, op);
  2730.  
  2731.     if (system_header_p)
  2732.       system_include_depth--;
  2733.  
  2734.     close (f);
  2735.   }
  2736. }
  2737.  
  2738. /* Process the contents of include file FNAME, already open on descriptor F,
  2739.    with output to OP.  */
  2740.  
  2741. finclude (f, fname, op)
  2742.      int f;
  2743.      char *fname;
  2744.      FILE_BUF *op;
  2745. {
  2746.   int st_mode;
  2747.   long st_size;
  2748.   long i;
  2749.   FILE_BUF *fp;            /* For input stack frame */
  2750.   int success = 0;
  2751.  
  2752.   CHECK_DEPTH (return;);
  2753.  
  2754.   if (file_size_and_mode (f, &st_mode, &st_size) < 0)
  2755.     goto nope;        /* Impossible? */
  2756.  
  2757.   fp = &instack[indepth + 1];
  2758.   bzero (fp, sizeof (FILE_BUF));
  2759.   fp->fname = fname;
  2760.   fp->length = 0;
  2761.   fp->lineno = 1;
  2762.   fp->if_stack = if_stack;
  2763.  
  2764.   if (st_mode & S_IFREG) {
  2765.     fp->buf = (U_CHAR *) alloca (st_size + 2);
  2766.     fp->bufp = fp->buf;
  2767.  
  2768.     /* Read the file contents, knowing that st_size is an upper bound
  2769.        on the number of bytes we can read.  */
  2770.     while (st_size > 0) {
  2771.       i = read (f, fp->buf + fp->length, st_size);
  2772.       if (i <= 0) {
  2773.     if (i == 0) break;
  2774.     goto nope;
  2775.       }
  2776.       fp->length += i;
  2777.       st_size -= i;
  2778.     }
  2779.   }
  2780.   else {
  2781.     /* Cannot count its file size before reading.
  2782.        First read the entire file into heap and
  2783.        copy them into buffer on stack. */
  2784.  
  2785.     U_CHAR *bufp;
  2786.     U_CHAR *basep;
  2787.     int bsize = 2000;
  2788.  
  2789.     st_size = 0;
  2790.     basep = (U_CHAR *) xmalloc (bsize + 2);
  2791.     bufp = basep;
  2792.  
  2793.     for (;;) {
  2794.       i = read (f, bufp, bsize - st_size);
  2795.       if (i < 0)
  2796.     goto nope;      /* error! */
  2797.       if (i == 0)
  2798.     break;    /* End of file */
  2799.       st_size += i;
  2800.       bufp += i;
  2801.       if (bsize == st_size) {    /* Buffer is full! */
  2802.       bsize *= 2;
  2803.       basep = (U_CHAR *) xrealloc (basep, bsize + 2);
  2804.       bufp = basep + st_size;    /* May have moved */
  2805.     }
  2806.     }
  2807.     fp->buf = (U_CHAR *) alloca (st_size + 2);
  2808.     fp->bufp = fp->buf;
  2809.     bcopy (basep, fp->buf, st_size);
  2810.     fp->length = st_size;
  2811.     free (basep);
  2812.   }
  2813.  
  2814.   if (!no_trigraphs)
  2815.     trigraph_pcp (fp);
  2816.  
  2817.   if (fp->length > 0 && fp->buf[fp->length-1] != '\n')
  2818.     fp->buf[fp->length++] = '\n';
  2819.   fp->buf[fp->length] = '\0';
  2820.  
  2821.   success = 1;
  2822.   indepth++;
  2823.  
  2824.   output_line_command (fp, op, 0, enter_file);
  2825.   rescan (op, 0);
  2826.   indepth--;
  2827.   output_line_command (&instack[indepth], op, 0, leave_file);
  2828.  
  2829. nope:
  2830.  
  2831.   if (!success)
  2832.     perror_with_name (fname);
  2833.  
  2834.   close (f);
  2835. }
  2836.  
  2837. /* The arglist structure is built by do_define to tell
  2838.    collect_definition where the argument names begin.  That
  2839.    is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
  2840.    would contain pointers to the strings x, y, and z.
  2841.    Collect_definition would then build a DEFINITION node,
  2842.    with reflist nodes pointing to the places x, y, and z had
  2843.    appeared.  So the arglist is just convenience data passed
  2844.    between these two routines.  It is not kept around after
  2845.    the current #define has been processed and entered into the
  2846.    hash table. */
  2847.  
  2848. struct arglist {
  2849.   struct arglist *next;
  2850.   U_CHAR *name;
  2851.   int length;
  2852.   int argno;
  2853. };
  2854.  
  2855. /* Process a #define command.
  2856. BUF points to the contents of the #define command, as a continguous string.
  2857. LIMIT points to the first character past the end of the definition.
  2858. KEYWORD is the keyword-table entry for #define.  */
  2859.  
  2860. do_define (buf, limit, op, keyword)
  2861.      U_CHAR *buf, *limit;
  2862.      FILE_BUF *op;
  2863.      struct directive *keyword;
  2864. {
  2865.   U_CHAR *bp;            /* temp ptr into input buffer */
  2866.   U_CHAR *symname;        /* remember where symbol name starts */
  2867.   int sym_length;        /* and how long it is */
  2868.  
  2869.   DEFINITION *defn;
  2870.   int arglengths = 0;        /* Accumulate lengths of arg names
  2871.                    plus number of args.  */
  2872.   int hashcode;
  2873.  
  2874.   bp = buf;
  2875.  
  2876.   while (is_hor_space[*bp])
  2877.     bp++;
  2878.   if (!is_idstart[*bp])
  2879.     warning ("macro name starts with a digit");
  2880.  
  2881.   symname = bp;            /* remember where it starts */
  2882.   while (is_idchar[*bp] && bp < limit) {
  2883.     bp++;
  2884.   }
  2885.   sym_length = bp - symname;
  2886.  
  2887.   /* lossage will occur if identifiers or control keywords are broken
  2888.      across lines using backslash.  This is not the right place to take
  2889.      care of that. */
  2890.  
  2891.   if (*bp == '(') {
  2892.     struct arglist *arg_ptrs = NULL;
  2893.     int argno = 0;
  2894.  
  2895.     bp++;            /* skip '(' */
  2896.     SKIP_WHITE_SPACE (bp);
  2897.  
  2898.     /* Loop over macro argument names.  */
  2899.     while (*bp != ')') {
  2900.       struct arglist *temp;
  2901.  
  2902.       temp = (struct arglist *) alloca (sizeof (struct arglist));
  2903.       temp->name = bp;
  2904.       temp->next = arg_ptrs;
  2905.       temp->argno = argno++;
  2906.       arg_ptrs = temp;
  2907.  
  2908.       if (!is_idstart[*bp])
  2909.     warning ("parameter name starts with a digit in #define");
  2910.  
  2911.       /* Find the end of the arg name.  */
  2912.       while (is_idchar[*bp]) {
  2913.     bp++;
  2914.       }
  2915.       temp->length = bp - temp->name;
  2916.       arglengths += temp->length + 2;
  2917.       SKIP_WHITE_SPACE (bp);
  2918.       if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
  2919.     error ("badly punctuated parameter list in #define");
  2920.     goto nope;
  2921.       }
  2922.       if (*bp == ',') {
  2923.     bp++;
  2924.     SKIP_WHITE_SPACE (bp);
  2925.       }
  2926.       if (bp >= limit) {
  2927.     error ("unterminated parameter list in #define");
  2928.     goto nope;
  2929.       }
  2930.     }
  2931.  
  2932.     ++bp;            /* skip paren */
  2933.     /* Skip exactly one space or tab if any.  */
  2934.     if (bp < limit && (*bp == ' ' || *bp == '\t')) ++bp;
  2935.     /* now everything from bp before limit is the definition. */
  2936.     defn = collect_expansion (bp, limit, argno, arg_ptrs);
  2937.  
  2938.     /* Now set defn->argnames to the result of concatenating
  2939.        the argument names in reverse order
  2940.        with comma-space between them.  */
  2941.     defn->argnames = (U_CHAR *) xmalloc (arglengths + 1);
  2942.     {
  2943.       struct arglist *temp;
  2944.       int i = 0;
  2945.       for (temp = arg_ptrs; temp; temp = temp->next) {
  2946.     bcopy (temp->name, &defn->argnames[i], temp->length);
  2947.     i += temp->length;
  2948.     if (temp->next != 0) {
  2949.       defn->argnames[i++] = ',';
  2950.       defn->argnames[i++] = ' ';
  2951.     }
  2952.       }
  2953.       defn->argnames[i] = 0;
  2954.     }
  2955.   } else {
  2956.     /* simple expansion or empty definition; gobble it */
  2957.     if (is_hor_space[*bp])
  2958.       ++bp;        /* skip exactly one blank/tab char */
  2959.     /* now everything from bp before limit is the definition. */
  2960.     defn = collect_expansion (bp, limit, -1, 0);
  2961.     defn->argnames = (U_CHAR *) "";
  2962.   }
  2963.  
  2964.   hashcode = hashf (symname, sym_length, HASHSIZE);
  2965.  
  2966.   {
  2967.     HASHNODE *hp;
  2968.     if ((hp = lookup (symname, sym_length, hashcode)) != NULL) {
  2969.       if (hp->type != T_MACRO
  2970.       || compare_defs (defn, hp->value.defn)) {
  2971.     U_CHAR *msg;            /* what pain... */
  2972.     msg = (U_CHAR *) alloca (sym_length + 20);
  2973.     bcopy (symname, msg, sym_length);
  2974.     strcpy ((char *) (msg + sym_length), " redefined");
  2975.     warning (msg);
  2976.       }
  2977.       /* Replace the old definition.  */
  2978.       hp->type = T_MACRO;
  2979.       hp->value.defn = defn;
  2980.     } else
  2981.       install (symname, sym_length, T_MACRO, defn, hashcode);
  2982.   }
  2983.  
  2984.   return 0;
  2985.  
  2986. nope:
  2987.  
  2988.   return 1;
  2989. }
  2990.  
  2991. /*
  2992.  * return zero if two DEFINITIONs are isomorphic
  2993.  */
  2994. int
  2995. compare_defs (d1, d2)
  2996.      DEFINITION *d1, *d2;
  2997. {
  2998.   register struct reflist *a1, *a2;
  2999.   register U_CHAR *p1 = d1->expansion;
  3000.   register U_CHAR *p2 = d2->expansion;
  3001.   int first = 1;
  3002.  
  3003.   if (d1->nargs != d2->nargs)
  3004.     return 1;
  3005.   if (strcmp ((char *)d1->argnames, (char *)d2->argnames))
  3006.     return 1;
  3007.   for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
  3008.        a1 = a1->next, a2 = a2->next) {
  3009.     if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
  3010.       || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
  3011.     || a1->argno != a2->argno
  3012.     || a1->stringify != a2->stringify
  3013.     || a1->raw_before != a2->raw_before
  3014.     || a1->raw_after != a2->raw_after)
  3015.       return 1;
  3016.     first = 0;
  3017.     p1 += a1->nchars;
  3018.     p2 += a2->nchars;
  3019.   }
  3020.   if (a1 != a2)
  3021.     return 1;
  3022.   if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
  3023.              p2, d2->length - (p2 - d2->expansion), 1))
  3024.     return 1;
  3025.   return 0;
  3026. }
  3027.  
  3028. /* Return 1 if two parts of two macro definitions are effectively different.
  3029.    One of the parts starts at BEG1 and has LEN1 chars;
  3030.    the other has LEN2 chars at BEG2.
  3031.    Any sequence of whitespace matches any other sequence of whitespace.
  3032.    FIRST means these parts are the first of a macro definition;
  3033.     so ignore leading whitespace entirely.
  3034.    LAST means these parts are the last of a macro definition;
  3035.     so ignore trailing whitespace entirely.  */
  3036.  
  3037. comp_def_part (first, beg1, len1, beg2, len2, last)
  3038.      int first;
  3039.      U_CHAR *beg1, *beg2;
  3040.      int len1, len2;
  3041.      int last;
  3042. {
  3043.   register U_CHAR *end1 = beg1 + len1;
  3044.   register U_CHAR *end2 = beg2 + len2;
  3045.   if (first) {
  3046.     while (beg1 != end1 && is_space[*beg1]) beg1++;
  3047.     while (beg2 != end2 && is_space[*beg2]) beg2++;
  3048.   }
  3049.   if (last) {
  3050.     while (beg1 != end1 && is_space[end1[-1]]) end1--;
  3051.     while (beg2 != end2 && is_space[end2[-1]]) end2--;
  3052.   }
  3053.   while (beg1 != end1 && beg2 != end2) {
  3054.     if (is_space[*beg1] && is_space[*beg2]) {
  3055.       while (beg1 != end1 && is_space[*beg1]) beg1++;
  3056.       while (beg2 != end2 && is_space[*beg2]) beg2++;
  3057.     } else if (*beg1 == *beg2) {
  3058.       beg1++; beg2++;
  3059.     } else break;
  3060.   }
  3061.   return (beg1 != end1) || (beg2 != end2);
  3062. }
  3063.  
  3064. /* Read a replacement list for a macro with parameters.
  3065.    Build the DEFINITION structure.
  3066.    Reads characters of text starting at BUF until LIMIT.
  3067.    ARGLIST specifies the formal parameters to look for
  3068.    in the text of the definition; NARGS is the number of args
  3069.    in that list, or -1 for a macro name that wants no argument list.
  3070.    MACRONAME is the macro name itself (so we can avoid recursive expansion)
  3071.    and NAMELEN is its length in characters.
  3072.    
  3073. Note that comments and backslash-newlines have already been deleted
  3074. from the argument.  */
  3075.  
  3076. /* Leading and trailing Space, Tab, etc. are converted to markers
  3077.    Newline Space, Newline Tab, etc.
  3078.    Newline Space makes a space in the final output
  3079.    but is discarded if stringified.  (Newline Tab is similar but
  3080.    makes a Tab instead.)
  3081.  
  3082.    If there is no trailing whitespace, a Newline Space is added at the end
  3083.    to prevent concatenation that would be contrary to the standard.  */
  3084.  
  3085. DEFINITION *
  3086. collect_expansion (buf, end, nargs, arglist)
  3087.      U_CHAR *buf, *end;
  3088.      int nargs;
  3089.      struct arglist *arglist;
  3090. {
  3091.   DEFINITION *defn;
  3092.   register U_CHAR *p, *limit, *lastp, *exp_p;
  3093.   struct reflist *endpat = NULL;
  3094.   /* Pointer to first nonspace after last ## seen.  */
  3095.   U_CHAR *concat = 0;
  3096.   /* Pointer to first nonspace after last single-# seen.  */
  3097.   U_CHAR *stringify = 0;
  3098.   int maxsize;
  3099.   int expected_delimiter = '\0';
  3100.  
  3101.   /* Scan thru the replacement list, ignoring comments and quoted
  3102.      strings, picking up on the macro calls.  It does a linear search
  3103.      thru the arg list on every potential symbol.  Profiling might say
  3104.      that something smarter should happen. */
  3105.  
  3106.   if (end < buf)
  3107.     abort ();
  3108.  
  3109.   /* Find the beginning of the trailing whitespace.  */
  3110.   /* Find end of leading whitespace.  */
  3111.   limit = end;
  3112.   p = buf;
  3113.   while (p < limit && is_space[limit[-1]]) limit--;
  3114.   while (p < limit && is_space[*p]) p++;
  3115.  
  3116.   /* Allocate space for the text in the macro definition.
  3117.      Leading and trailing whitespace chars need 2 bytes each.
  3118.      Each other input char may or may not need 1 byte,
  3119.      so this is an upper bound.
  3120.      The extra 2 are for invented trailing newline-marker and final null.  */
  3121.   maxsize = (sizeof (DEFINITION)
  3122.          + 2 * (end - limit) + 2 * (p - buf)
  3123.          + (limit - p) + 3);
  3124.   defn = (DEFINITION *) xcalloc (1, maxsize);
  3125.  
  3126.   defn->nargs = nargs;
  3127.   exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
  3128.   lastp = exp_p;
  3129.  
  3130.   p = buf;
  3131.  
  3132.   /* Convert leading whitespace to Newline-markers.  */
  3133.   while (p < limit && is_space[*p]) {
  3134.     *exp_p++ = '\n';
  3135.     *exp_p++ = *p++;
  3136.   }
  3137.  
  3138.   /* Process the main body of the definition.  */
  3139.   while (p < limit) {
  3140.     int skipped_arg = 0;
  3141.     register U_CHAR c = *p++;
  3142.  
  3143.     *exp_p++ = c;
  3144.  
  3145.     if (!traditional) {
  3146.       switch (c) {
  3147.       case '\'':
  3148.       case '\"':
  3149.     for (; p < limit && *p != c; p++) {
  3150.       *exp_p++ = *p;
  3151.       if (*p == '\\') {
  3152.         *exp_p++ = *++p;
  3153.       }
  3154.     }
  3155.     *exp_p++ = *p++;
  3156.     break;
  3157.  
  3158.     /* Special hack: if a \# is written in the #define
  3159.        include a # in the definition.  This is useless for C code
  3160.        but useful for preprocessing other things.  */
  3161.  
  3162.       case '\\':
  3163.     if (p < limit && *p == '#') {
  3164.       /* Pass through this # */
  3165.       exp_p--;
  3166.       *exp_p++ = *p++;
  3167.     } else if (p < limit) {
  3168.       /* Otherwise backslash goes through but makes next char ordinary.  */
  3169.       *exp_p++ = *p++;
  3170.     }
  3171.     break;
  3172.  
  3173.       case '#':
  3174.     if (p < limit && *p == '#') {
  3175.       /* ##: concatenate preceding and following tokens.  */
  3176.       /* Take out the first #, discard preceding whitespace.  */
  3177.       exp_p--;
  3178.       while (exp_p > lastp && is_hor_space[exp_p[-1]])
  3179.         --exp_p;
  3180.       /* Skip the second #.  */
  3181.       p++;
  3182.       /* Discard following whitespace.  */
  3183.       SKIP_WHITE_SPACE (p);
  3184.       concat = p;
  3185.     } else {
  3186.       /* Single #: stringify following argument ref.
  3187.          Don't leave the # in the expansion.  */
  3188.       exp_p--;
  3189.       SKIP_WHITE_SPACE (p);
  3190.       if (p == limit || ! is_idstart[*p] || nargs <= 0)
  3191.         error ("# operator should be followed by a macro argument name\n");
  3192.       else
  3193.         stringify = p;
  3194.     }
  3195.     break;
  3196.       }
  3197.     } else {
  3198.       /* In -traditional mode, recognize arguments inside strings and
  3199.      and character constants, and ignore special properties of #.
  3200.      Arguments inside strings are considered "stringified", but no
  3201.      extra quote marks are supplied.  */
  3202.       switch (c) {
  3203.       case '\'':
  3204.       case '\"':
  3205.     if (expected_delimiter != '\0') {
  3206.       if (c == expected_delimiter)
  3207.         expected_delimiter = '\0';
  3208.     } else
  3209.       expected_delimiter = c;
  3210.     break;
  3211.  
  3212.       case '\\':
  3213.     /* Backslash quotes delimiters and itself, but not macro args.  */
  3214.     if (expected_delimiter != 0 && p < limit
  3215.         && (*p == expected_delimiter || *p == '\\')) {
  3216.       *exp_p++ = *p++;
  3217.       continue;
  3218.     }
  3219.     break;
  3220.  
  3221.       case '/':
  3222.     if (expected_delimiter != '\0') /* No comments inside strings.  */
  3223.       break;
  3224.     if (*p == '*') {
  3225.       /* If we find a comment that wasn't removed by handle_directive,
  3226.          this must be -traditional.  So replace the comment with
  3227.          nothing at all.  */
  3228.       exp_p--;
  3229.       p += 1;
  3230.       while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
  3231.         p++;
  3232.       /* Mark this as a concatenation-point, as if it had been ##.  */
  3233.       concat = p;
  3234.     }
  3235.     break;
  3236.       }
  3237.     }
  3238.  
  3239.     if (is_idchar[c] && nargs > 0) {
  3240.       U_CHAR *id_beg = p - 1;
  3241.       int id_len;
  3242.  
  3243.       --exp_p;
  3244.       while (p != limit && is_idchar[*p]) p++;
  3245.       id_len = p - id_beg;
  3246.  
  3247.       if (is_idstart[c]) {
  3248.     register struct arglist *arg;
  3249.  
  3250.     for (arg = arglist; arg != NULL; arg = arg->next) {
  3251.       struct reflist *tpat;
  3252.  
  3253.       if (arg->name[0] == c
  3254.           && arg->length == id_len
  3255.           && strncmp (arg->name, id_beg, id_len) == 0) {
  3256.         /* make a pat node for this arg and append it to the end of
  3257.            the pat list */
  3258.         tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
  3259.         tpat->next = NULL;
  3260.         tpat->raw_before = concat == id_beg;
  3261.         tpat->raw_after = 0;
  3262.         tpat->stringify = (traditional ? expected_delimiter != '\0'
  3263.                    : stringify == id_beg);
  3264.  
  3265.         if (endpat == NULL)
  3266.           defn->pattern = tpat;
  3267.         else
  3268.           endpat->next = tpat;
  3269.         endpat = tpat;
  3270.  
  3271.         tpat->argno = arg->argno;
  3272.         tpat->nchars = exp_p - lastp;
  3273.         {
  3274.           register U_CHAR *p1 = p;
  3275.           SKIP_WHITE_SPACE (p1);
  3276.           if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
  3277.         tpat->raw_after = 1;
  3278.         }
  3279.         lastp = exp_p;    /* place to start copying from next time */
  3280.         skipped_arg = 1;
  3281.         break;
  3282.       }
  3283.     }
  3284.       }
  3285.  
  3286.       /* If this was not a macro arg, copy it into the expansion.  */
  3287.       if (! skipped_arg) {
  3288.     register U_CHAR *lim1 = p;
  3289.     p = id_beg;
  3290.     while (p != lim1)
  3291.       *exp_p++ = *p++;
  3292.     if (stringify == id_beg)
  3293.       error ("# operator should be followed by a macro argument name\n");
  3294.       }
  3295.     }
  3296.   }
  3297.  
  3298.   if (limit < end) {
  3299.     /* Convert trailing whitespace to Newline-markers.  */
  3300.     while (limit < end && is_space[*limit]) {
  3301.       *exp_p++ = '\n';
  3302.       *exp_p++ = *limit++;
  3303.     }
  3304.   } else if (!traditional) {
  3305.     /* There is no trailing whitespace, so invent some.  */
  3306.     *exp_p++ = '\n';
  3307.     *exp_p++ = ' ';
  3308.   }
  3309.  
  3310.   *exp_p = '\0';
  3311.  
  3312.   defn->length = exp_p - defn->expansion;
  3313.  
  3314.   /* Crash now if we overrun the allocated size.  */
  3315.   if (defn->length + 1 > maxsize)
  3316.     abort ();
  3317.  
  3318. #if 0
  3319. /* This isn't worth the time it takes.  */
  3320.   /* give back excess storage */
  3321.   defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
  3322. #endif
  3323.  
  3324.   return defn;
  3325. }
  3326.  
  3327. /*
  3328.  * interpret #line command.  Remembers previously seen fnames
  3329.  * in its very own hash table.
  3330.  */
  3331. #define FNAME_HASHSIZE 37
  3332.  
  3333. do_line (buf, limit, op, keyword)
  3334.      U_CHAR *buf, *limit;
  3335.      FILE_BUF *op;
  3336.      struct directive *keyword;
  3337. {
  3338.   register U_CHAR *bp;
  3339.   FILE_BUF *ip = &instack[indepth];
  3340.   FILE_BUF tem;
  3341.   int new_lineno;
  3342.   enum file_change_code file_change = same_file;
  3343.  
  3344.   /* Expand any macros.  */
  3345.   tem = expand_to_temp_buffer (buf, limit, 0);
  3346.  
  3347.   /* Point to macroexpanded line, which is null-terminated now.  */
  3348.   bp = tem.buf;
  3349.   SKIP_WHITE_SPACE (bp);
  3350.  
  3351.   if (!isdigit (*bp)) {
  3352.     error ("invalid format #line command");
  3353.     return;
  3354.   }
  3355.  
  3356.   /* The Newline at the end of this line remains to be processed.
  3357.      To put the next line at the specified line number,
  3358.      we must store a line number now that is one less.  */
  3359.   new_lineno = atoi (bp) - 1;
  3360.  
  3361.   /* skip over the line number.  */
  3362.   while (isdigit (*bp))
  3363.     bp++;
  3364.   if (*bp && !is_space[*bp]) {
  3365.     error ("invalid format #line command");
  3366.     return;
  3367.   }
  3368.     
  3369.   SKIP_WHITE_SPACE (bp);
  3370.  
  3371.   if (*bp == '\"') {
  3372.     static HASHNODE *fname_table[FNAME_HASHSIZE];
  3373.     HASHNODE *hp, **hash_bucket;
  3374.     U_CHAR *fname;
  3375.     int fname_length;
  3376.  
  3377.     fname = ++bp;
  3378.  
  3379.     while (*bp && *bp != '\"')
  3380.       bp++;
  3381.     if (*bp != '\"') {
  3382.       error ("invalid format #line command");
  3383.       return;
  3384.     }
  3385.  
  3386.     fname_length = bp - fname;
  3387.  
  3388.     bp++;
  3389.     SKIP_WHITE_SPACE (bp);
  3390.     if (*bp) {
  3391.       if (*bp == '1')
  3392.     file_change = enter_file;
  3393.       else if (*bp == '2')
  3394.     file_change = leave_file;
  3395.       else {
  3396.     error ("invalid format #line command");
  3397.     return;
  3398.       }
  3399.  
  3400.       bp++;
  3401.       SKIP_WHITE_SPACE (bp);
  3402.       if (*bp) {
  3403.     error ("invalid format #line command");
  3404.     return;
  3405.       }
  3406.     }
  3407.  
  3408.     hash_bucket =
  3409.       &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
  3410.     for (hp = *hash_bucket; hp != NULL; hp = hp->next)
  3411.       if (hp->length == fname_length &&
  3412.       strncmp (hp->value.cpval, fname, fname_length) == 0) {
  3413.     ip->fname = hp->value.cpval;
  3414.     break;
  3415.       }
  3416.     if (hp == 0) {
  3417.       /* Didn't find it; cons up a new one.  */
  3418.       hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
  3419.       hp->next = *hash_bucket;
  3420.       *hash_bucket = hp;
  3421.  
  3422.       hp->length = fname_length;
  3423.       ip->fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
  3424.       bcopy (fname, hp->value.cpval, fname_length);
  3425.     }
  3426.   } else if (*bp) {
  3427.     error ("invalid format #line command");
  3428.     return;
  3429.   }
  3430.  
  3431.   ip->lineno = new_lineno;
  3432.   output_line_command (ip, op, 0, file_change);
  3433.   check_expand (op, ip->length - (ip->bufp - ip->buf));
  3434. }
  3435.  
  3436. /*
  3437.  * remove all definitions of symbol from symbol table.
  3438.  * according to un*x /lib/cpp, it is not an error to undef
  3439.  * something that has no definitions, so it isn't one here either.
  3440.  */
  3441. do_undef (buf, limit, op, keyword)
  3442.      U_CHAR *buf, *limit;
  3443.      FILE_BUF *op;
  3444.      struct directive *keyword;
  3445. {
  3446.   HASHNODE *hp;
  3447.  
  3448.   SKIP_WHITE_SPACE (buf);
  3449.  
  3450.   while ((hp = lookup (buf, -1, -1)) != NULL) {
  3451.     if (hp->type != T_MACRO)
  3452.       error ("undefining `%s'", hp->name);
  3453.     delete_macro (hp);
  3454.   }
  3455. }
  3456.  
  3457. /*
  3458.  * Report a fatal error detected by the program we are processing.
  3459.  * Use the text of the line in the error message, then terminate.
  3460.  * (We use error() because it prints the filename & line#.)
  3461.  */
  3462. do_error (buf, limit, op, keyword)
  3463.      U_CHAR *buf, *limit;
  3464.      FILE_BUF *op;
  3465.      struct directive *keyword;
  3466. {
  3467.   int length = limit - buf;
  3468.   char *copy = (char *) xmalloc (length + 1);
  3469.   bcopy (buf, copy, length);
  3470.   copy[length] = 0;
  3471.   SKIP_WHITE_SPACE (copy);
  3472.   error ("#error %s", copy);
  3473.   exit (FATAL_EXIT_CODE);
  3474. }
  3475.  
  3476. /* Remember the name of the current file being read from so that we can
  3477.    avoid ever including it again.  */
  3478.  
  3479. do_once ()
  3480. {
  3481.   int i;
  3482.   FILE_BUF *ip = NULL;
  3483.  
  3484.   for (i = indepth; i >= 0; i--)
  3485.     if (instack[i].fname != NULL) {
  3486.       ip = &instack[i];
  3487.       break;
  3488.     }
  3489.  
  3490.   if (ip != NULL)
  3491.     {
  3492.       struct file_name_list *new;
  3493.  
  3494.       new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
  3495.       new->next = dont_repeat_files;
  3496.       dont_repeat_files = new;
  3497.       new->fname = savestring (ip->fname);
  3498.     }
  3499. }
  3500.  
  3501. /* #pragma and its argument line have already been copied to the output file.
  3502.    Here just check for recognized pragmas.  */
  3503.  
  3504. do_pragma (buf, limit)
  3505.      U_CHAR *buf, *limit;
  3506. {
  3507.   while (*buf == ' ' || *buf == '\t')
  3508.     buf++;
  3509.   if (!strncmp (buf, "once", 4))
  3510.     do_once ();
  3511. }
  3512.  
  3513. #if 0
  3514. /* This was a fun hack, but #pragma seems to start to be useful.
  3515.    By failing to recognize it, we pass it through unchanged to cc1.  */
  3516.  
  3517. /*
  3518.  * the behavior of the #pragma directive is implementation defined.
  3519.  * this implementation defines it as follows.
  3520.  */
  3521. do_pragma ()
  3522. {
  3523.   close (0);
  3524.   if (open ("/dev/tty", O_RDONLY, 0666) != 0)
  3525.     goto nope;
  3526.   close (1);
  3527.   if (open ("/dev/tty", O_WRONLY, 0666) != 1)
  3528.     goto nope;
  3529.   execl ("/usr/games/hack", "#pragma", 0);
  3530.   execl ("/usr/games/rogue", "#pragma", 0);
  3531.   execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
  3532.   execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
  3533. nope:
  3534.   fatal ("You are in a maze of twisty compiler features, all different");
  3535. }
  3536. #endif
  3537.  
  3538. /* Just ignore #sccs, on systems where we define it at all.  */
  3539. do_sccs ()
  3540. {
  3541.   if (pedantic)
  3542.     error ("ANSI C does not allow #sccs");
  3543. }
  3544.  
  3545. /*
  3546.  * handle #if command by
  3547.  *   1) inserting special `defined' keyword into the hash table
  3548.  *    that gets turned into 0 or 1 by special_symbol (thus,
  3549.  *    if the luser has a symbol called `defined' already, it won't
  3550.  *      work inside the #if command)
  3551.  *   2) rescan the input into a temporary output buffer
  3552.  *   3) pass the output buffer to the yacc parser and collect a value
  3553.  *   4) clean up the mess left from steps 1 and 2.
  3554.  *   5) call conditional_skip to skip til the next #endif (etc.),
  3555.  *      or not, depending on the value from step 3.
  3556.  */
  3557.  
  3558. do_if (buf, limit, op, keyword)
  3559.      U_CHAR *buf, *limit;
  3560.      FILE_BUF *op;
  3561.      struct directive *keyword;
  3562. {
  3563.   int value;
  3564.   FILE_BUF *ip = &instack[indepth];
  3565.  
  3566.   value = eval_if_expression (buf, limit - buf);
  3567.   conditional_skip (ip, value == 0, T_IF);
  3568. }
  3569.  
  3570. /*
  3571.  * handle a #elif directive by not changing  if_stack  either.
  3572.  * see the comment above do_else.
  3573.  */
  3574.  
  3575. do_elif (buf, limit, op, keyword)
  3576.      U_CHAR *buf, *limit;
  3577.      FILE_BUF *op;
  3578.      struct directive *keyword;
  3579. {
  3580.   int value;
  3581.   FILE_BUF *ip = &instack[indepth];
  3582.  
  3583.   if (if_stack == instack[indepth].if_stack) {
  3584.     error ("#elif not within a conditional");
  3585.     return;
  3586.   } else {
  3587.     if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
  3588.       error ("#elif after #else");
  3589.       fprintf (stderr, " (matches line %d", if_stack->lineno);
  3590.       if (if_stack->fname != NULL && ip->fname != NULL &&
  3591.       strcmp (if_stack->fname, ip->fname) != 0)
  3592.     fprintf (stderr, ", file %s", if_stack->fname);
  3593.       fprintf (stderr, ")\n");
  3594.     }
  3595.     if_stack->type = T_ELIF;
  3596.   }
  3597.  
  3598.   if (if_stack->if_succeeded)
  3599.     skip_if_group (ip, 0);
  3600.   else {
  3601.     value = eval_if_expression (buf, limit - buf);
  3602.     if (value == 0)
  3603.       skip_if_group (ip, 0);
  3604.     else {
  3605.       ++if_stack->if_succeeded;    /* continue processing input */
  3606.       output_line_command (ip, op, 1, same_file);
  3607.     }
  3608.   }
  3609. }
  3610.  
  3611. /*
  3612.  * evaluate a #if expression in BUF, of length LENGTH,
  3613.  * then parse the result as a C expression and return the value as an int.
  3614.  */
  3615. int
  3616. eval_if_expression (buf, length)
  3617.      U_CHAR *buf;
  3618.      int length;
  3619. {
  3620.   FILE_BUF temp_obuf;
  3621.   HASHNODE *save_defined;
  3622.   int value;
  3623.  
  3624.   save_defined = install ("defined", -1, T_SPEC_DEFINED, 0, -1);
  3625.   temp_obuf = expand_to_temp_buffer (buf, buf + length, 0);
  3626.   delete_macro (save_defined);    /* clean up special symbol */
  3627.  
  3628.   value = parse_c_expression (temp_obuf.buf);
  3629.  
  3630.   free (temp_obuf.buf);
  3631.  
  3632.   return value;
  3633. }
  3634.  
  3635. /*
  3636.  * routine to handle ifdef/ifndef.  Try to look up the symbol,
  3637.  * then do or don't skip to the #endif/#else/#elif depending
  3638.  * on what directive is actually being processed.
  3639.  */
  3640. do_xifdef (buf, limit, op, keyword)
  3641.      U_CHAR *buf, *limit;
  3642.      FILE_BUF *op;
  3643.      struct directive *keyword;
  3644. {
  3645.   int skip;
  3646.   FILE_BUF *ip = &instack[indepth];
  3647.   U_CHAR *end; 
  3648.  
  3649.   /* Discard leading and trailing whitespace.  */
  3650.   SKIP_WHITE_SPACE (buf);
  3651.   while (limit != buf && is_hor_space[limit[-1]]) limit--;
  3652.  
  3653.   /* Find the end of the identifier at the beginning.  */
  3654.   for (end = buf; is_idchar[*end]; end++);
  3655.  
  3656.   if (end == buf) {
  3657.     skip = (keyword->type == T_IFDEF);
  3658.     if (! traditional)
  3659.       warning (end == limit ? "#%s with no argument"
  3660.            : "#%s argument starts with punctuation",
  3661.            keyword->name);
  3662.   } else {
  3663.     if (pedantic && buf[0] >= '0' && buf[0] <= '9')
  3664.       warning ("#%s argument starts with a digit", keyword->name);
  3665.     else if (end != limit && !traditional)
  3666.       warning ("garbage at end of #%s argument", keyword->name);
  3667.  
  3668.     skip = (lookup (buf, end-buf, -1) == NULL) ^ (keyword->type == T_IFNDEF);
  3669.   }
  3670.  
  3671.   conditional_skip (ip, skip, T_IF);
  3672. }
  3673.  
  3674. /*
  3675.  * push TYPE on stack; then, if SKIP is nonzero, skip ahead.
  3676.  */
  3677. void
  3678. conditional_skip (ip, skip, type)
  3679.      FILE_BUF *ip;
  3680.      int skip;
  3681.      enum node_type type;
  3682. {
  3683.   IF_STACK_FRAME *temp;
  3684.  
  3685.   temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
  3686.   temp->fname = ip->fname;
  3687.   temp->lineno = ip->lineno;
  3688.   temp->next = if_stack;
  3689.   if_stack = temp;
  3690.  
  3691.   if_stack->type = type;
  3692.  
  3693.   if (skip != 0) {
  3694.     skip_if_group (ip, 0);
  3695.     return;
  3696.   } else {
  3697.     ++if_stack->if_succeeded;
  3698.     output_line_command (ip, &outbuf, 1, same_file);
  3699.   }
  3700. }
  3701.  
  3702. /*
  3703.  * skip to #endif, #else, or #elif.  adjust line numbers, etc.
  3704.  * leaves input ptr at the sharp sign found.
  3705.  * If ANY is nonzero, return at next directive of any sort.
  3706.  */
  3707. void
  3708. skip_if_group (ip, any)
  3709.      FILE_BUF *ip;
  3710.      int any;
  3711. {
  3712.   register U_CHAR *bp = ip->bufp, *cp;
  3713.   register U_CHAR *endb = ip->buf + ip->length;
  3714.   struct directive *kt;
  3715.   IF_STACK_FRAME *save_if_stack = if_stack; /* don't pop past here */
  3716.   U_CHAR *beg_of_line = bp;
  3717.  
  3718.   while (bp < endb) {
  3719.     switch (*bp++) {
  3720.     case '/':            /* possible comment */
  3721.       if (*bp == '\\' && bp[1] == '\n')
  3722.     newline_fix (bp);
  3723.       if (*bp == '*'
  3724.       || (cplusplus && *bp == '/')) {
  3725.     ip->bufp = ++bp;
  3726.     bp = skip_to_end_of_comment (ip, &ip->lineno);
  3727.       }
  3728.       break;
  3729.     case '\"':
  3730.     case '\'':
  3731.       if (!traditional)
  3732.     bp = skip_quoted_string (bp - 1, endb, ip->lineno, &ip->lineno, 0, 0);
  3733.       break;
  3734.     case '\\':
  3735.       /* Char after backslash loses its special meaning.  */
  3736.       if (bp < endb) {
  3737.     if (*bp == '\n')
  3738.       ++ip->lineno;        /* But do update the line-count.  */
  3739.     bp++;
  3740.       }
  3741.       break;
  3742.     case '\n':
  3743.       ++ip->lineno;
  3744.       beg_of_line = bp;
  3745.       break;
  3746.     case '#':
  3747.       ip->bufp = bp - 1;
  3748.  
  3749.       /* # keyword: a # must be first nonblank char on the line */
  3750.       if (beg_of_line == 0)
  3751.     break;
  3752.       /* Scan from start of line, skipping whitespace, comments
  3753.      and backslash-newlines, and see if we reach this #.
  3754.      If not, this # is not special.  */
  3755.       bp = beg_of_line;
  3756.       while (1) {
  3757.     if (is_hor_space[*bp])
  3758.       bp++;
  3759.     else if (*bp == '\\' && bp[1] == '\n')
  3760.       bp += 2;
  3761.     else if (*bp == '/' && bp[1] == '*') {
  3762.       bp += 2;
  3763.       while (!(*bp == '*' && bp[1] == '/'))
  3764.         bp++;
  3765.       bp += 2;
  3766.     }
  3767.     else if (cplusplus && *bp == '/' && bp[1] == '/') {
  3768.       bp += 2;
  3769.       while (*bp++ != '\n') ;
  3770.         }
  3771.     else break;
  3772.       }
  3773.       if (bp != ip->bufp) {
  3774.     bp = ip->bufp + 1;    /* Reset bp to after the #.  */
  3775.     break;
  3776.       }
  3777.  
  3778.       bp = ip->bufp + 1;        /* point at '#' */
  3779.  
  3780.       /* Skip whitespace and \-newline.  */
  3781.       while (1) {
  3782.     if (is_hor_space[*bp])
  3783.       bp++;
  3784.     else if (*bp == '\\' && bp[1] == '\n')
  3785.       bp += 2;
  3786.     else break;
  3787.       }
  3788.  
  3789.       cp = bp;
  3790.  
  3791.       /* Now find end of directive name.
  3792.      If we encounter a backslash-newline, exchange it with any following
  3793.      symbol-constituents so that we end up with a contiguous name.  */
  3794.  
  3795.       while (1) {
  3796.     if (is_idchar[*bp])
  3797.       bp++;
  3798.     else {
  3799.       if (*bp == '\\' && bp[1] == '\n')
  3800.         name_newline_fix (bp);
  3801.       if (is_idchar[*bp])
  3802.         bp++;
  3803.       else break;
  3804.     }
  3805.       }
  3806.  
  3807.       for (kt = directive_table; kt->length >= 0; kt++) {
  3808.     IF_STACK_FRAME *temp;
  3809.     if (strncmp (cp, kt->name, kt->length) == 0
  3810.         && !is_idchar[cp[kt->length]]) {
  3811.  
  3812.       /* If we are asked to return on next directive,
  3813.          do so now.  */
  3814.       if (any)
  3815.         return;
  3816.  
  3817.       switch (kt->type) {
  3818.       case T_IF:
  3819.       case T_IFDEF:
  3820.       case T_IFNDEF:
  3821.         temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
  3822.         temp->next = if_stack;
  3823.         if_stack = temp;
  3824.         temp->lineno = ip->lineno;
  3825.         temp->fname = ip->fname;
  3826.         temp->type = kt->type;
  3827.         break;
  3828.       case T_ELSE:
  3829.       case T_ENDIF:
  3830.         if (pedantic && if_stack != save_if_stack)
  3831.           validate_else (bp);
  3832.       case T_ELIF:
  3833.         if (if_stack == instack[indepth].if_stack) {
  3834.           error ("#%s not within a conditional", kt->name);
  3835.           break;
  3836.         }
  3837.         else if (if_stack == save_if_stack)
  3838.           return;        /* found what we came for */
  3839.  
  3840.         if (kt->type != T_ENDIF) {
  3841.           if (if_stack->type == T_ELSE)
  3842.         error ("#else or #elif after #else");
  3843.           if_stack->type = kt->type;
  3844.           break;
  3845.         }
  3846.  
  3847.         temp = if_stack;
  3848.         if_stack = if_stack->next;
  3849.         free (temp);
  3850.         break;
  3851.       }
  3852.       break;
  3853.     }
  3854.       }
  3855.     }
  3856.   }
  3857.   ip->bufp = bp;
  3858.   /* after this returns, rescan will exit because ip->bufp
  3859.      now points to the end of the buffer.
  3860.      rescan is responsible for the error message also.  */
  3861. }
  3862.  
  3863. /*
  3864.  * handle a #else directive.  Do this by just continuing processing
  3865.  * without changing  if_stack ;  this is so that the error message
  3866.  * for missing #endif's etc. will point to the original #if.  It
  3867.  * is possible that something different would be better.
  3868.  */
  3869. do_else (buf, limit, op, keyword)
  3870.      U_CHAR *buf, *limit;
  3871.      FILE_BUF *op;
  3872.      struct directive *keyword;
  3873. {
  3874.   FILE_BUF *ip = &instack[indepth];
  3875.  
  3876.   if (pedantic) {
  3877.     SKIP_WHITE_SPACE (buf);
  3878.     if (buf != limit)
  3879.       warning ("text following #else violates ANSI standard");
  3880.   }
  3881.  
  3882.   if (if_stack == instack[indepth].if_stack) {
  3883.     error ("#else not within a conditional");
  3884.     return;
  3885.   } else {
  3886.     if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
  3887.       error ("#else after #else");
  3888.       fprintf (stderr, " (matches line %d", if_stack->lineno);
  3889.       if (strcmp (if_stack->fname, ip->fname) != 0)
  3890.     fprintf (stderr, ", file %s", if_stack->fname);
  3891.       fprintf (stderr, ")\n");
  3892.     }
  3893.     if_stack->type = T_ELSE;
  3894.   }
  3895.  
  3896.   if (if_stack->if_succeeded)
  3897.     skip_if_group (ip, 0);
  3898.   else {
  3899.     ++if_stack->if_succeeded;    /* continue processing input */
  3900.     output_line_command (ip, op, 1, same_file);
  3901.   }
  3902. }
  3903.  
  3904. /*
  3905.  * unstack after #endif command
  3906.  */
  3907. do_endif (buf, limit, op, keyword)
  3908.      U_CHAR *buf, *limit;
  3909.      FILE_BUF *op;
  3910.      struct directive *keyword;
  3911. {
  3912.   if (pedantic) {
  3913.     SKIP_WHITE_SPACE (buf);
  3914.     if (buf != limit)
  3915.       warning ("text following #endif violates ANSI standard");
  3916.   }
  3917.  
  3918.   if (if_stack == instack[indepth].if_stack)
  3919.     error ("unbalanced #endif");
  3920.   else {
  3921.     IF_STACK_FRAME *temp = if_stack;
  3922.     if_stack = if_stack->next;
  3923.     free (temp);
  3924.     output_line_command (&instack[indepth], op, 1, same_file);
  3925.   }
  3926. }
  3927.  
  3928. /* When an #else or #endif is found while skipping failed conditional,
  3929.    if -pedantic was specified, this is called to warn about text after
  3930.    the command name.  P points to the first char after the command name.  */
  3931.  
  3932. validate_else (p)
  3933.      register U_CHAR *p;
  3934. {
  3935.   /* Advance P over whitespace and comments.  */
  3936.   while (1) {
  3937.     if (*p == '\\' && p[1] == '\n')
  3938.       p += 2;
  3939.     if (is_hor_space[*p])
  3940.       p++;
  3941.     else if (*p == '/') {
  3942.       if (p[1] == '\\' && p[2] == '\n')
  3943.     newline_fix (p + 1);
  3944.       if (p[1] == '*') {
  3945.     p += 2;
  3946.     /* Don't bother warning about unterminated comments
  3947.        since that will happen later.  Just be sure to exit.  */
  3948.     while (*p) {
  3949.       if (p[1] == '\\' && p[2] == '\n')
  3950.         newline_fix (p + 1);
  3951.       if (*p == '*' && p[1] == '/') {
  3952.         p += 2;
  3953.         break;
  3954.       }
  3955.       p++;
  3956.     }
  3957.       }
  3958.       else if (cplusplus && p[1] == '/') {
  3959.     p += 2;
  3960.     while (*p && *p++ != '\n') ;
  3961.       }
  3962.     } else break;
  3963.   }
  3964.   if (*p && *p != '\n')
  3965.     warning ("text following #else or #endif violates ANSI standard");
  3966. }
  3967.  
  3968. /*
  3969.  * Skip a comment, assuming the input ptr immediately follows the
  3970.  * initial slash-star.  Bump line counter as necessary.
  3971.  * (The canonical line counter is &ip->lineno).
  3972.  * Don't use this routine (or the next one) if bumping the line
  3973.  * counter is not sufficient to deal with newlines in the string.
  3974.  */
  3975. U_CHAR *
  3976. skip_to_end_of_comment (ip, line_counter)
  3977.      register FILE_BUF *ip;
  3978.      int *line_counter;        /* place to remember newlines, or NULL */
  3979. {
  3980.   register U_CHAR *limit = ip->buf + ip->length;
  3981.   register U_CHAR *bp = ip->bufp;
  3982.   FILE_BUF *op = &outbuf;    /* JF */
  3983.   int output = put_out_comments && !line_counter;
  3984.  
  3985.     /* JF this line_counter stuff is a crock to make sure the
  3986.        comment is only put out once, no matter how many times
  3987.        the comment is skipped.  It almost works */
  3988.   if (output) {
  3989.     *op->bufp++ = '/';
  3990.     *op->bufp++ = '*';
  3991.   }
  3992.   if (cplusplus && bp[-1] == '/') {
  3993.     if (output) {
  3994.       while (bp < limit)
  3995.     if ((*op->bufp++ = *bp++) == '\n') {
  3996.       bp--;
  3997.       break;
  3998.     }
  3999.       op->bufp[-1] = '*';
  4000.       *op->bufp++ = '/';
  4001.       *op->bufp++ = '\n';
  4002.     } else {
  4003.       while (bp < limit) {
  4004.     if (*bp++ == '\n') {
  4005.       bp--;
  4006.       break;
  4007.     }
  4008.       }
  4009.     }
  4010.     ip->bufp = bp;
  4011.     return bp;
  4012.   }
  4013.   while (bp < limit) {
  4014.     if (output)
  4015.       *op->bufp++ = *bp;
  4016.     switch (*bp++) {
  4017.     case '\n':
  4018.       if (line_counter != NULL)
  4019.     ++*line_counter;
  4020.       if (output)
  4021.     ++op->lineno;
  4022.       break;
  4023.     case '*':
  4024.       if (*bp == '\\' && bp[1] == '\n')
  4025.     newline_fix (bp);
  4026.       if (*bp == '/') {
  4027.         if (output)
  4028.       *op->bufp++ = '/';
  4029.     ip->bufp = ++bp;
  4030.     return bp;
  4031.       }
  4032.       break;
  4033.     }
  4034.   }
  4035.   ip->bufp = bp;
  4036.   return bp;
  4037. }
  4038.  
  4039. /*
  4040.  * Skip over a quoted string.  BP points to the opening quote.
  4041.  * Returns a pointer after the closing quote.  Don't go past LIMIT.
  4042.  * START_LINE is the line number of the starting point (but it need
  4043.  * not be valid if the starting point is inside a macro expansion).
  4044.  *
  4045.  * The input stack state is not changed.
  4046.  *
  4047.  * If COUNT_NEWLINES is nonzero, it points to an int to increment
  4048.  * for each newline passed.
  4049.  *
  4050.  * If BACKSLASH_NEWLINES_P is nonzero, store 1 thru it
  4051.  * if we pass a backslash-newline.
  4052.  *
  4053.  * If EOFP is nonzero, set *EOFP to 1 if the string is unterminated.
  4054.  */
  4055. U_CHAR *
  4056. skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p, eofp)
  4057.      register U_CHAR *bp;
  4058.      register U_CHAR *limit;
  4059.      int start_line;
  4060.      int *count_newlines;
  4061.      int *backslash_newlines_p;
  4062.      int *eofp;
  4063. {
  4064.   register U_CHAR c, match;
  4065.  
  4066.   match = *bp++;
  4067.   while (1) {
  4068.     if (bp >= limit) {
  4069.       error_with_line (line_for_error (start_line),
  4070.                "unterminated string or character constant");
  4071.       if (eofp)
  4072.     *eofp = 1;
  4073.       break;
  4074.     }
  4075.     c = *bp++;
  4076.     if (c == '\\') {
  4077.       while (*bp == '\\' && bp[1] == '\n') {
  4078.     if (backslash_newlines_p)
  4079.       *backslash_newlines_p = 1;
  4080.     if (count_newlines)
  4081.       ++*count_newlines;
  4082.     bp += 2;
  4083.       }
  4084.       if (*bp == '\n' && count_newlines) {
  4085.     if (backslash_newlines_p)
  4086.       *backslash_newlines_p = 1;
  4087.     ++*count_newlines;
  4088.       }
  4089.       bp++;
  4090.     } else if (c == '\n') {
  4091.       if (match == '\'') {
  4092.     error_with_line (line_for_error (start_line),
  4093.              "unterminated character constant");
  4094.     bp--;
  4095.     if (eofp)
  4096.       *eofp = 1;
  4097.     break;
  4098.       }
  4099.       if (traditional) {    /* Unterminated strings are 'legal'.  */
  4100.     if (eofp)
  4101.       *eofp = 1;
  4102.     break;
  4103.       }
  4104.       if (count_newlines)
  4105.     ++*count_newlines;
  4106.     } else if (c == match)
  4107.       break;
  4108.   }
  4109.   return bp;
  4110. }
  4111.  
  4112. /*
  4113.  * write out a #line command, for instance, after an #include file.
  4114.  * If CONDITIONAL is nonzero, we can omit the #line if it would
  4115.  * appear to be a no-op, and we can output a few newlines instead
  4116.  * if we want to increase the line number by a small amount.
  4117.  * FILE_CHANGE says whether we are entering a file, leaving, or neither.
  4118.  */
  4119.  
  4120. void
  4121. output_line_command (ip, op, conditional, file_change)
  4122.      FILE_BUF *ip, *op;
  4123.      int conditional;
  4124.      enum file_change_code file_change;
  4125. {
  4126.   int len;
  4127.   char line_cmd_buf[500];
  4128.  
  4129.   if (no_line_commands
  4130.       || ip->fname == NULL
  4131.       || no_output) {
  4132.     op->lineno = ip->lineno;
  4133.     return;
  4134.   }
  4135.  
  4136.   if (conditional) {
  4137.     if (ip->lineno == op->lineno)
  4138.       return;
  4139.  
  4140.     /* If the inherited line number is a little too small,
  4141.        output some newlines instead of a #line command.  */
  4142.     if (ip->lineno > op->lineno && ip->lineno < op->lineno + 8) {
  4143.       check_expand (op, 10);
  4144.       while (ip->lineno > op->lineno) {
  4145.     *op->bufp++ = '\n';
  4146.     op->lineno++;
  4147.       }
  4148.       return;
  4149.     }
  4150.   }
  4151.  
  4152. #ifdef OUTPUT_LINE_COMMANDS
  4153.   sprintf (line_cmd_buf, "#line %d \"%s\"", ip->lineno, ip->fname);
  4154. #else
  4155.   sprintf (line_cmd_buf, "# %d \"%s\"", ip->lineno, ip->fname);
  4156. #endif
  4157.   if (file_change != same_file)
  4158.     strcat (line_cmd_buf, file_change == enter_file ? " 1" : " 2");
  4159.   len = strlen (line_cmd_buf);
  4160.   line_cmd_buf[len++] = '\n';
  4161.   check_expand (op, len + 1);
  4162.   if (op->bufp > op->buf && op->bufp[-1] != '\n')
  4163.     *op->bufp++ = '\n';
  4164.   bcopy (line_cmd_buf, op->bufp, len);
  4165.   op->bufp += len;
  4166.   op->lineno = ip->lineno;
  4167. }
  4168.  
  4169. /* This structure represents one parsed argument in a macro call.
  4170.    `raw' points to the argument text as written (`raw_length' is its length).
  4171.    `expanded' points to the argument's macro-expansion
  4172.    (its length is `expand_length').
  4173.    `stringified_length' is the length the argument would have
  4174.    if stringified.
  4175.    `free1' and `free2', if nonzero, point to blocks to be freed
  4176.    when the macro argument data is no longer needed.  */
  4177.  
  4178. struct argdata {
  4179.   U_CHAR *raw, *expanded;
  4180.   int raw_length, expand_length;
  4181.   int stringified_length;
  4182.   U_CHAR *free1, *free2;
  4183.   char newlines;
  4184.   char comments;
  4185. };
  4186.  
  4187. /* Expand a macro call.
  4188.    HP points to the symbol that is the macro being called.
  4189.    Put the result of expansion onto the input stack
  4190.    so that subsequent input by our caller will use it.
  4191.  
  4192.    If macro wants arguments, caller has already verified that
  4193.    an argument list follows; arguments come from the input stack.  */
  4194.  
  4195. void
  4196. macroexpand (hp, op)
  4197.      HASHNODE *hp;
  4198.      FILE_BUF *op;
  4199. {
  4200.   int nargs;
  4201.   DEFINITION *defn = hp->value.defn;
  4202.   register U_CHAR *xbuf;
  4203.   int xbuf_len;
  4204.   int start_line = instack[indepth].lineno;
  4205.  
  4206.   CHECK_DEPTH (return;);
  4207.  
  4208.   /* it might not actually be a macro.  */
  4209.   if (hp->type != T_MACRO) {
  4210.     special_symbol (hp, op);
  4211.     return;
  4212.   }
  4213.  
  4214.   nargs = defn->nargs;
  4215.  
  4216.   if (nargs >= 0) {
  4217.     register int i;
  4218.     struct argdata *args;
  4219.     char *parse_error = 0;
  4220.  
  4221.     args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
  4222.  
  4223.     for (i = 0; i < nargs; i++) {
  4224.       args[i].raw = args[i].expanded = (U_CHAR *) "";
  4225.       args[i].raw_length = args[i].expand_length
  4226.     = args[i].stringified_length = 0;
  4227.       args[i].free1 = args[i].free2 = 0;
  4228.     }
  4229.  
  4230.     /* Parse all the macro args that are supplied.  I counts them.
  4231.        The first NARGS args are stored in ARGS.
  4232.        The rest are discarded.  */
  4233.     i = 0;
  4234.     do {
  4235.       /* Discard the open-parenthesis or comma before the next arg.  */
  4236.       ++instack[indepth].bufp;
  4237.       parse_error
  4238.     = macarg ((i < nargs || (nargs == 0 && i == 0)) ? &args[i] : 0);
  4239.       if (parse_error)
  4240.     {
  4241.       error_with_line (line_for_error (start_line), parse_error);
  4242.       break;
  4243.     }
  4244.       i++;
  4245.     } while (*instack[indepth].bufp != ')');
  4246.  
  4247.     /* If we got one arg but it was just whitespace, call that 0 args.  */
  4248.     if (i == 1) {
  4249.       register U_CHAR *bp = args[0].raw;
  4250.       register U_CHAR *lim = bp + args[0].raw_length;
  4251.       while (bp != lim && is_space[*bp]) bp++;
  4252.       if (bp == lim)
  4253.     i = 0;
  4254.     }
  4255.  
  4256.     if (nargs == 0 && i > 0)
  4257.       error ("arguments given to macro `%s'", hp->name);
  4258.     else if (i < nargs) {
  4259.       /* traditional C allows foo() if foo wants one argument.  */
  4260.       if (nargs == 1 && i == 0 && traditional)
  4261.     ;
  4262.       else if (i == 0)
  4263.     error ("no args to macro `%s'", hp->name);
  4264.       else if (i == 1)
  4265.     error ("only 1 arg to macro `%s'", hp->name);
  4266.       else
  4267.     error ("only %d args to macro `%s'", i, hp->name);
  4268.     } else if (i > nargs)
  4269.       error ("too many (%d) args to macro `%s'", i, hp->name);
  4270.  
  4271.     /* Swallow the closeparen.  */
  4272.     ++instack[indepth].bufp;
  4273.  
  4274.     /* If macro wants zero args, we parsed the arglist for checking only.
  4275.        Read directly from the macro definition.  */
  4276.     if (nargs == 0) {
  4277.       xbuf = defn->expansion;
  4278.       xbuf_len = defn->length;
  4279.     } else {
  4280.       register U_CHAR *exp = defn->expansion;
  4281.       register int offset;    /* offset in expansion,
  4282.                    copied a piece at a time */
  4283.       register int totlen;    /* total amount of exp buffer filled so far */
  4284.  
  4285.       register struct reflist *ap;
  4286.  
  4287.       /* Macro really takes args.  Compute the expansion of this call.  */
  4288.  
  4289.       /* Compute length in characters of the macro's expansion.  */
  4290.       xbuf_len = defn->length;
  4291.       for (ap = defn->pattern; ap != NULL; ap = ap->next) {
  4292.     if (ap->stringify)
  4293.       xbuf_len += args[ap->argno].stringified_length;
  4294.     else if (ap->raw_before || ap->raw_after)
  4295.       xbuf_len += args[ap->argno].raw_length;
  4296.     else
  4297.       xbuf_len += args[ap->argno].expand_length;
  4298.       }
  4299.  
  4300.       xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
  4301.  
  4302.       /* Generate in XBUF the complete expansion
  4303.      with arguments substituted in.
  4304.      TOTLEN is the total size generated so far.
  4305.      OFFSET is the index in the definition
  4306.      of where we are copying from.  */
  4307.       offset = totlen = 0;
  4308.       for (ap = defn->pattern; ap != NULL; ap = ap->next) {
  4309.     register struct argdata *arg = &args[ap->argno];
  4310.  
  4311.     for (i = 0; i < ap->nchars; i++)
  4312.       xbuf[totlen++] = exp[offset++];
  4313.  
  4314.     if (ap->stringify != 0) {
  4315.       int arglen = arg->raw_length;
  4316.       int escaped = 0;
  4317.       int in_string = 0;
  4318.       int c;
  4319.       i = 0;
  4320.       while (i < arglen
  4321.          && (c = arg->raw[i], is_space[c]))
  4322.         i++;
  4323.       while (i < arglen
  4324.          && (c = arg->raw[arglen - 1], is_space[c]))
  4325.         arglen--;
  4326.       if (!traditional)
  4327.         xbuf[totlen++] = '\"'; /* insert beginning quote */
  4328.       for (; i < arglen; i++) {
  4329.         c = arg->raw[i];
  4330.  
  4331.         /* Special markers Newline Space
  4332.            generate nothing for a stringified argument.  */
  4333.         if (c == '\n' && arg->raw[i+1] != '\n') {
  4334.           i++;
  4335.           continue;
  4336.         }
  4337.  
  4338.         /* Internal sequences of whitespace are replaced by one space.  */
  4339.         if (c == '\n' ? arg->raw[i+1] == '\n' : is_space[c]) {
  4340.           while (1) {
  4341.         if (c == '\n' && arg->raw[i+1] == '\n')
  4342.           i += 2;
  4343.         else if (c != '\n' && is_space[c])
  4344.           i++;
  4345.         else break;
  4346.         c = arg->raw[i];
  4347.           }
  4348.           i--;
  4349.           c = ' ';
  4350.         }
  4351.  
  4352.         if (escaped)
  4353.           escaped = 0;
  4354.         else {
  4355.           if (c == '\\')
  4356.         escaped = 1;
  4357.           if (in_string && c == in_string)
  4358.         in_string = 0;
  4359.           else if (c == '\"' || c == '\'')
  4360.         in_string = c;
  4361.         }
  4362.  
  4363.         /* Escape these chars */
  4364.         if (c == '\"' || (in_string && c == '\\'))
  4365.           xbuf[totlen++] = '\\';
  4366.         if (isprint (c))
  4367.           xbuf[totlen++] = c;
  4368.         else {
  4369.           sprintf ((char *) &xbuf[totlen], "\\%03o", (unsigned int) c);
  4370.           totlen += 4;
  4371.         }
  4372.       }
  4373.       if (!traditional)
  4374.         xbuf[totlen++] = '\"'; /* insert ending quote */
  4375.     } else if (ap->raw_before || ap->raw_after) {
  4376.       U_CHAR *p1 = arg->raw;
  4377.       U_CHAR *l1 = p1 + arg->raw_length;
  4378.       if (ap->raw_before) {
  4379.         while (p1 != l1 && is_space[*p1]) p1++;
  4380.         while (p1 != l1 && is_idchar[*p1])
  4381.           xbuf[totlen++] = *p1++;
  4382.         /* Delete any no-reexpansion marker that follows
  4383.            an identifier at the beginning of the argument
  4384.            if the argument is concatenated with what precedes it.  */
  4385.         if (p1[0] == '\n' && p1[1] == '-')
  4386.           p1 += 2;
  4387.       }
  4388.       if (ap->raw_after) {
  4389.         /* Arg is concatenated after: delete trailing whitespace,
  4390.            whitespace markers, and no-reexpansion markers.  */
  4391.         while (p1 != l1) {
  4392.           if (is_space[l1[-1]]) l1--;
  4393.           else if (l1[-1] == '-') {
  4394.         U_CHAR *p2 = l1 - 1;
  4395.         /* If a `-' is preceded by an odd number of newlines then it
  4396.            and the last newline are a no-reexpansion marker.  */
  4397.         while (p2 != p1 && p2[-1] == '\n') p2--;
  4398.         if ((l1 - 1 - p2) & 1) {
  4399.           l1 -= 2;
  4400.         }
  4401.         else break;
  4402.           }
  4403.           else break;
  4404.         }
  4405.       }
  4406.       bcopy (p1, xbuf + totlen, l1 - p1);
  4407.       totlen += l1 - p1;
  4408.     } else {
  4409.       bcopy (arg->expanded, xbuf + totlen, arg->expand_length);
  4410.       totlen += arg->expand_length;
  4411.     }
  4412.  
  4413.     if (totlen > xbuf_len)
  4414.       abort ();
  4415.       }
  4416.  
  4417.       /* if there is anything left of the definition
  4418.      after handling the arg list, copy that in too. */
  4419.  
  4420.       for (i = offset; i < defn->length; i++)
  4421.     xbuf[totlen++] = exp[i];
  4422.  
  4423.       xbuf[totlen] = 0;
  4424.       xbuf_len = totlen;
  4425.  
  4426.       for (i = 0; i < nargs; i++) {
  4427.     if (args[i].free1 != 0)
  4428.       free (args[i].free1);
  4429.     if (args[i].free2 != 0)
  4430.       free (args[i].free2);
  4431.       }
  4432.     }
  4433.   } else {
  4434.     xbuf = defn->expansion;
  4435.     xbuf_len = defn->length;
  4436.   }
  4437.  
  4438.   /* Now put the expansion on the input stack
  4439.      so our caller will commence reading from it.  */
  4440.   {
  4441.     register FILE_BUF *ip2;
  4442.  
  4443.     ip2 = &instack[++indepth];
  4444.  
  4445.     ip2->fname = 0;
  4446.     ip2->lineno = 0;
  4447.     ip2->buf = xbuf;
  4448.     ip2->length = xbuf_len;
  4449.     ip2->bufp = xbuf;
  4450.     ip2->free_ptr = (nargs > 0) ? xbuf : 0;
  4451.     ip2->macro = hp;
  4452.     ip2->if_stack = if_stack;
  4453.  
  4454.     /* Recursive macro use sometimes works traditionally.
  4455.        #define foo(x,y) bar(x(y,0), y)
  4456.        foo(foo, baz)  */
  4457.  
  4458.     if (!traditional)
  4459.       hp->type = T_DISABLED;
  4460.   }
  4461. }
  4462.  
  4463. /*
  4464.  * Parse a macro argument and store the info on it into *ARGPTR.
  4465.  * Return nonzero to indicate a syntax error.
  4466.  */
  4467.  
  4468. char *
  4469. macarg (argptr)
  4470.      register struct argdata *argptr;
  4471. {
  4472.   FILE_BUF *ip = &instack[indepth];
  4473.   int paren = 0;
  4474.   int newlines = 0;
  4475.   int comments = 0;
  4476.  
  4477.   /* Try to parse as much of the argument as exists at this
  4478.      input stack level.  */
  4479.   U_CHAR *bp = macarg1 (ip->bufp, ip->buf + ip->length,
  4480.             &paren, &newlines, &comments);
  4481.  
  4482.   /* If we find the end of the argument at this level,
  4483.      set up *ARGPTR to point at it in the input stack.  */
  4484.   if (!(ip->fname != 0 && (newlines != 0 || comments != 0))
  4485.       && bp != ip->buf + ip->length) {
  4486.     if (argptr != 0) {
  4487.       argptr->raw = ip->bufp;
  4488.       argptr->raw_length = bp - ip->bufp;
  4489.     }
  4490.     ip->bufp = bp;
  4491.   } else {
  4492.     /* This input stack level ends before the macro argument does.
  4493.        We must pop levels and keep parsing.
  4494.        Therefore, we must allocate a temporary buffer and copy
  4495.        the macro argument into it.  */
  4496.     int bufsize = bp - ip->bufp;
  4497.     int extra = newlines;
  4498.     U_CHAR *buffer = (U_CHAR *) xmalloc (bufsize + extra + 1);
  4499.     int final_start = 0;
  4500.  
  4501.     bcopy (ip->bufp, buffer, bufsize);
  4502.     ip->bufp = bp;
  4503.     ip->lineno += newlines;
  4504.  
  4505.     while (bp == ip->buf + ip->length) {
  4506.       if (instack[indepth].macro == 0) {
  4507.     free (buffer);
  4508.     return "unterminated macro call";
  4509.       }
  4510.       ip->macro->type = T_MACRO;
  4511.       free (ip->buf);
  4512.       ip = &instack[--indepth];
  4513.       newlines = 0;
  4514.       comments = 0;
  4515.       bp = macarg1 (ip->bufp, ip->buf + ip->length, &paren,
  4516.             &newlines, &comments);
  4517.       final_start = bufsize;
  4518.       bufsize += bp - ip->bufp;
  4519.       extra += newlines;
  4520.       buffer = (U_CHAR *) xrealloc (buffer, bufsize + extra + 1);
  4521.       bcopy (ip->bufp, buffer + bufsize - (bp - ip->bufp), bp - ip->bufp);
  4522.       ip->bufp = bp;
  4523.       ip->lineno += newlines;
  4524.     }
  4525.  
  4526.     /* Now, if arg is actually wanted, record its raw form,
  4527.        discarding comments and duplicating newlines in whatever
  4528.        part of it did not come from a macro expansion.
  4529.        EXTRA space has been preallocated for duplicating the newlines.
  4530.        FINAL_START is the index of the start of that part.  */
  4531.     if (argptr != 0) {
  4532.       argptr->raw = buffer;
  4533.       argptr->raw_length = bufsize;
  4534.       argptr->free1 = buffer;
  4535.       argptr->newlines = newlines;
  4536.       argptr->comments = comments;
  4537.       if ((newlines || comments) && ip->fname != 0)
  4538.     argptr->raw_length
  4539.       = final_start +
  4540.         discard_comments (argptr->raw + final_start,
  4541.                   argptr->raw_length - final_start,
  4542.                   newlines);
  4543.       argptr->raw[argptr->raw_length] = 0;
  4544.       if (argptr->raw_length > bufsize + extra)
  4545.     abort ();
  4546.     }
  4547.   }
  4548.  
  4549.   /* If we are not discarding this argument,
  4550.      macroexpand it and compute its length as stringified.
  4551.      All this info goes into *ARGPTR.  */
  4552.  
  4553.   if (argptr != 0) {
  4554.     FILE_BUF obuf;
  4555.     register U_CHAR *buf, *lim;
  4556.     register int totlen;
  4557.  
  4558.     obuf = expand_to_temp_buffer (argptr->raw,
  4559.                   argptr->raw + argptr->raw_length,
  4560.                   1);
  4561.  
  4562.     argptr->expanded = obuf.buf;
  4563.     argptr->expand_length = obuf.length;
  4564.     argptr->free2 = obuf.buf;
  4565.  
  4566.     buf = argptr->raw;
  4567.     lim = buf + argptr->raw_length;
  4568.  
  4569.     while (buf != lim && is_space[*buf])
  4570.       buf++;
  4571.     while (buf != lim && is_space[lim[-1]])
  4572.       lim--;
  4573.     totlen = traditional ? 0 : 2;    /* Count opening and closing quote.  */
  4574.     while (buf != lim) {
  4575.       register U_CHAR c = *buf++;
  4576.       totlen++;
  4577.       /* Internal sequences of whitespace are replaced by one space.  */
  4578.       if (is_space[c])
  4579.     SKIP_ALL_WHITE_SPACE (buf);
  4580.       else if (c == '\"' || c == '\\') /* escape these chars */
  4581.     totlen++;
  4582.       else if (!isprint (c))
  4583.     totlen += 3;
  4584.     }
  4585.     argptr->stringified_length = totlen;
  4586.   }
  4587.   return 0;
  4588. }
  4589.  
  4590. /* Scan text from START (inclusive) up to LIMIT (exclusive),
  4591.    counting parens in *DEPTHPTR,
  4592.    and return if reach LIMIT
  4593.    or before a `)' that would make *DEPTHPTR negative
  4594.    or before a comma when *DEPTHPTR is zero.
  4595.    Single and double quotes are matched and termination
  4596.    is inhibited within them.  Comments also inhibit it.
  4597.    Value returned is pointer to stopping place.
  4598.  
  4599.    Increment *NEWLINES each time a newline is passed.
  4600.    Set *COMMENTS to 1 if a comment is seen.  */
  4601.  
  4602. U_CHAR *
  4603. macarg1 (start, limit, depthptr, newlines, comments)
  4604.      U_CHAR *start;
  4605.      register U_CHAR *limit;
  4606.      int *depthptr, *newlines, *comments;
  4607. {
  4608.   register U_CHAR *bp = start;
  4609.  
  4610.   while (bp < limit) {
  4611.     switch (*bp) {
  4612.     case '(':
  4613.       (*depthptr)++;
  4614.       break;
  4615.     case ')':
  4616.       if (--(*depthptr) < 0)
  4617.     return bp;
  4618.       break;
  4619.     case '\\':
  4620.       /* Backslash makes following char not special.  */
  4621.       if (bp + 1 < limit) bp++;
  4622.       break;
  4623.     case '\n':
  4624.       ++*newlines;
  4625.       break;
  4626.     case '/':
  4627.       if (bp[1] == '\\' && bp[2] == '\n')
  4628.     newline_fix (bp + 1);
  4629.       if (cplusplus && bp[1] == '/') {
  4630.     *comments = 1;
  4631.     bp += 2;
  4632.     while (bp < limit && *bp++ != '\n') ;
  4633.     ++*newlines;
  4634.     break;
  4635.       }
  4636.       if (bp[1] != '*' || bp + 1 >= limit)
  4637.     break;
  4638.       *comments = 1;
  4639.       bp += 2;
  4640.       while (bp + 1 < limit) {
  4641.     if (bp[0] == '*'
  4642.         && bp[1] == '\\' && bp[2] == '\n')
  4643.       newline_fix (bp + 1);
  4644.     if (bp[0] == '*' && bp[1] == '/')
  4645.       break;
  4646.     if (*bp == '\n') ++*newlines;
  4647.     bp++;
  4648.       }
  4649.       break;
  4650.     case '\'':
  4651.     case '\"':
  4652.       {
  4653.     int quotec;
  4654.     for (quotec = *bp++; bp + 1 < limit && *bp != quotec; bp++) {
  4655.       if (*bp == '\\') {
  4656.         bp++;
  4657.         if (*bp == '\n')
  4658.           ++*newlines;
  4659.         while (*bp == '\\' && bp[1] == '\n') {
  4660.           bp += 2;
  4661.         }
  4662.       } else if (*bp == '\n') {
  4663.         ++*newlines;
  4664.         if (quotec == '\'')
  4665.           break;
  4666.       }
  4667.     }
  4668.       }
  4669.       break;
  4670.     case ',':
  4671.       if ((*depthptr) == 0)
  4672.     return bp;
  4673.       break;
  4674.     }
  4675.     bp++;
  4676.   }
  4677.  
  4678.   return bp;
  4679. }
  4680.  
  4681. /* Discard comments and duplicate newlines
  4682.    in the string of length LENGTH at START,
  4683.    except inside of string constants.
  4684.    The string is copied into itself with its beginning staying fixed.  
  4685.  
  4686.    NEWLINES is the number of newlines that must be duplicated.
  4687.    We assume that that much extra space is available past the end
  4688.    of the string.  */
  4689.  
  4690. int
  4691. discard_comments (start, length, newlines)
  4692.      U_CHAR *start;
  4693.      int length;
  4694.      int newlines;
  4695. {
  4696.   register U_CHAR *ibp;
  4697.   register U_CHAR *obp;
  4698.   register U_CHAR *limit;
  4699.   register int c;
  4700.  
  4701.   /* If we have newlines to duplicate, copy everything
  4702.      that many characters up.  Then, in the second part,
  4703.      we will have room to insert the newlines
  4704.      while copying down.
  4705.      NEWLINES may actually be too large, because it counts
  4706.      newlines in string constants, and we don't duplicate those.
  4707.      But that does no harm.  */
  4708.   if (newlines > 0) {
  4709.     ibp = start + length;
  4710.     obp = ibp + newlines;
  4711.     limit = start;
  4712.     while (limit != ibp)
  4713.       *--obp = *--ibp;
  4714.   }
  4715.  
  4716.   ibp = start + newlines;
  4717.   limit = start + length + newlines;
  4718.   obp = start;
  4719.  
  4720.   while (ibp < limit) {
  4721.     *obp++ = c = *ibp++;
  4722.     switch (c) {
  4723.     case '\n':
  4724.       /* Duplicate the newline.  */
  4725.       *obp++ = '\n';
  4726.       break;
  4727.  
  4728.     case '/':
  4729.       if (*ibp == '\\' && ibp[1] == '\n')
  4730.     newline_fix (ibp);
  4731.       /* Delete any comment.  */
  4732.       if (cplusplus && ibp[0] == '/') {
  4733.     obp--;
  4734.     ibp++;
  4735.     while (ibp < limit && *ibp++ != '\n') ;
  4736.     break;
  4737.       }
  4738.       if (ibp[0] != '*' || ibp + 1 >= limit)
  4739.     break;
  4740.       obp--;
  4741.       ibp++;
  4742.       while (ibp + 1 < limit) {
  4743.     if (ibp[0] == '*'
  4744.         && ibp[1] == '\\' && ibp[2] == '\n')
  4745.       newline_fix (ibp + 1);
  4746.     if (ibp[0] == '*' && ibp[1] == '/')
  4747.       break;
  4748.     ibp++;
  4749.       }
  4750.       ibp += 2;
  4751.       break;
  4752.  
  4753.     case '\'':
  4754.     case '\"':
  4755.       /* Notice and skip strings, so that we don't
  4756.      think that comments start inside them,
  4757.      and so we don't duplicate newlines in them.  */
  4758.       {
  4759.     int quotec = c;
  4760.     while (ibp < limit) {
  4761.       *obp++ = c = *ibp++;
  4762.       if (c == quotec)
  4763.         break;
  4764.       if (c == '\n' && quotec == '\'')
  4765.         break;
  4766.       if (c == '\\' && ibp < limit) {
  4767.         while (*ibp == '\\' && ibp[1] == '\n')
  4768.           ibp += 2;
  4769.         *obp++ = *ibp++;
  4770.       }
  4771.     }
  4772.       }
  4773.       break;
  4774.     }
  4775.   }
  4776.  
  4777.   return obp - start;
  4778. }
  4779.  
  4780. /*
  4781.  * error - print error message and increment count of errors.
  4782.  */
  4783. error (msg, arg1, arg2, arg3)
  4784.      char *msg;
  4785. {
  4786.   int i;
  4787.   FILE_BUF *ip = NULL;
  4788.  
  4789.   for (i = indepth; i >= 0; i--)
  4790.     if (instack[i].fname != NULL) {
  4791.       ip = &instack[i];
  4792.       break;
  4793.     }
  4794.  
  4795.   if (ip != NULL)
  4796.     fprintf (stderr, "%s:%d: ", ip->fname, ip->lineno);
  4797.   fprintf (stderr, msg, arg1, arg2, arg3);
  4798.   fprintf (stderr, "\n");
  4799.   errors++;
  4800.   return 0;
  4801. }
  4802.  
  4803. /* Error including a message from `errno'.  */
  4804.  
  4805. error_from_errno (name)
  4806.      char *name;
  4807. {
  4808.   int i;
  4809.   FILE_BUF *ip = NULL;
  4810.   extern int errno, sys_nerr;
  4811.   extern char *sys_errlist[];
  4812.  
  4813.   for (i = indepth; i >= 0; i--)
  4814.     if (instack[i].fname != NULL) {
  4815.       ip = &instack[i];
  4816.       break;
  4817.     }
  4818.  
  4819.   if (ip != NULL)
  4820.     fprintf (stderr, "%s:%d: ", ip->fname, ip->lineno);
  4821.  
  4822.   if (errno < sys_nerr)
  4823.     fprintf (stderr, "%s: %s\n", name, sys_errlist[errno]);
  4824.   else
  4825.     fprintf (stderr, "%s: undocumented I/O error\n", name);
  4826.  
  4827.   errors++;
  4828.   return 0;
  4829. }
  4830.  
  4831. /* Print error message but don't count it.  */
  4832.  
  4833. warning (msg, arg1, arg2, arg3)
  4834.      char *msg;
  4835. {
  4836.   int i;
  4837.   FILE_BUF *ip = NULL;
  4838.  
  4839.   for (i = indepth; i >= 0; i--)
  4840.     if (instack[i].fname != NULL) {
  4841.       ip = &instack[i];
  4842.       break;
  4843.     }
  4844.  
  4845.   if (ip != NULL)
  4846.     fprintf (stderr, "%s:%d: ", ip->fname, ip->lineno);
  4847.   fprintf (stderr, "warning: ");
  4848.   fprintf (stderr, msg, arg1, arg2, arg3);
  4849.   fprintf (stderr, "\n");
  4850.   return 0;
  4851. }
  4852.  
  4853. error_with_line (line, msg, arg1, arg2, arg3)
  4854.      int line;
  4855.      char *msg;
  4856. {
  4857.   int i;
  4858.   FILE_BUF *ip = NULL;
  4859.  
  4860.   for (i = indepth; i >= 0; i--)
  4861.     if (instack[i].fname != NULL) {
  4862.       ip = &instack[i];
  4863.       break;
  4864.     }
  4865.  
  4866.   if (ip != NULL)
  4867.     fprintf (stderr, "%s:%d: ", ip->fname, line);
  4868.   fprintf (stderr, msg, arg1, arg2, arg3);
  4869.   fprintf (stderr, "\n");
  4870.   errors++;
  4871.   return 0;
  4872. }
  4873.  
  4874. /* Return the line at which an error occurred.
  4875.    The error is not necessarily associated with the current spot
  4876.    in the input stack, so LINE says where.  LINE will have been
  4877.    copied from ip->lineno for the current input level.
  4878.    If the current level is for a file, we return LINE.
  4879.    But if the current level is not for a file, LINE is meaningless.
  4880.    In that case, we return the lineno of the innermost file.  */
  4881. int
  4882. line_for_error (line)
  4883.      int line;
  4884. {
  4885.   int i;
  4886.   int line1 = line;
  4887.  
  4888.   for (i = indepth; i >= 0; ) {
  4889.     if (instack[i].fname != 0)
  4890.       return line1;
  4891.     i--;
  4892.     if (i < 0)
  4893.       return 0;
  4894.     line1 = instack[i].lineno;
  4895.   }
  4896. }
  4897.  
  4898. /*
  4899.  * If OBUF doesn't have NEEDED bytes after OPTR, make it bigger.
  4900.  *
  4901.  * As things stand, nothing is ever placed in the output buffer to be
  4902.  * removed again except when it's KNOWN to be part of an identifier,
  4903.  * so flushing and moving down everything left, instead of expanding,
  4904.  * should work ok.
  4905.  */
  4906.  
  4907. int
  4908. grow_outbuf (obuf, needed)
  4909.      register FILE_BUF *obuf;
  4910.      register int needed;
  4911. {
  4912.   register U_CHAR *p;
  4913.   int minsize;
  4914.  
  4915.   if (obuf->length - (obuf->bufp - obuf->buf) > needed)
  4916.     return;
  4917.  
  4918.   /* Make it at least twice as big as it is now.  */
  4919.   obuf->length *= 2;
  4920.   /* Make it have at least 150% of the free space we will need.  */
  4921.   minsize = (3 * needed) / 2 + (obuf->bufp - obuf->buf);
  4922.   if (minsize > obuf->length)
  4923.     obuf->length = minsize;
  4924.  
  4925.   if ((p = (U_CHAR *) xrealloc (obuf->buf, obuf->length)) == NULL)
  4926.     memory_full ();
  4927.  
  4928.   obuf->bufp = p + (obuf->bufp - obuf->buf);
  4929.   obuf->buf = p;
  4930. }
  4931.  
  4932. /* Symbol table for macro names and special symbols */
  4933.  
  4934. /*
  4935.  * install a name in the main hash table, even if it is already there.
  4936.  *   name stops with first non alphanumeric, except leading '#'.
  4937.  * caller must check against redefinition if that is desired.
  4938.  * delete_macro () removes things installed by install () in fifo order.
  4939.  * this is important because of the `defined' special symbol used
  4940.  * in #if, and also if pushdef/popdef directives are ever implemented.
  4941.  *
  4942.  * If LEN is >= 0, it is the length of the name.
  4943.  * Otherwise, compute the length by scanning the entire name.
  4944.  *
  4945.  * If HASH is >= 0, it is the precomputed hash code.
  4946.  * Otherwise, compute the hash code.
  4947.  */
  4948. HASHNODE *
  4949. install (name, len, type, value, hash)
  4950.      U_CHAR *name;
  4951.      int len;
  4952.      enum node_type type;
  4953.      int value;
  4954.      int hash;
  4955.         /* watch out here if sizeof (U_CHAR *) != sizeof (int) */
  4956. {
  4957.   register HASHNODE *hp;
  4958.   register int i, bucket;
  4959.   register U_CHAR *p, *q;
  4960.  
  4961.   if (len < 0) {
  4962.     p = name;
  4963.     while (is_idchar[*p])
  4964.       p++;
  4965.     len = p - name;
  4966.   }
  4967.  
  4968.   if (hash < 0)
  4969.     hash = hashf (name, len, HASHSIZE);
  4970.  
  4971.   i = sizeof (HASHNODE) + len + 1;
  4972.   hp = (HASHNODE *) xmalloc (i);
  4973.   bucket = hash;
  4974.   hp->bucket_hdr = &hashtab[bucket];
  4975.   hp->next = hashtab[bucket];
  4976.   hashtab[bucket] = hp;
  4977.   hp->prev = NULL;
  4978.   if (hp->next != NULL)
  4979.     hp->next->prev = hp;
  4980.   hp->type = type;
  4981.   hp->length = len;
  4982.   hp->value.ival = value;
  4983.   hp->name = ((U_CHAR *) hp) + sizeof (HASHNODE);
  4984.   p = hp->name;
  4985.   q = name;
  4986.   for (i = 0; i < len; i++)
  4987.     *p++ = *q++;
  4988.   hp->name[len] = 0;
  4989.   return hp;
  4990. }
  4991.  
  4992. /*
  4993.  * find the most recent hash node for name name (ending with first
  4994.  * non-identifier char) installed by install
  4995.  *
  4996.  * If LEN is >= 0, it is the length of the name.
  4997.  * Otherwise, compute the length by scanning the entire name.
  4998.  *
  4999.  * If HASH is >= 0, it is the precomputed hash code.
  5000.  * Otherwise, compute the hash code.
  5001.  */
  5002. HASHNODE *
  5003. lookup (name, len, hash)
  5004.      U_CHAR *name;
  5005.      int len;
  5006.      int hash;
  5007. {
  5008.   register U_CHAR *bp;
  5009.   register HASHNODE *bucket;
  5010.  
  5011.   if (len < 0) {
  5012.     for (bp = name; is_idchar[*bp]; bp++) ;
  5013.     len = bp - name;
  5014.   }
  5015.  
  5016.   if (hash < 0)
  5017.     hash = hashf (name, len, HASHSIZE);
  5018.  
  5019.   bucket = hashtab[hash];
  5020.   while (bucket) {
  5021.     if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
  5022.       return bucket;
  5023.     bucket = bucket->next;
  5024.   }
  5025.   return NULL;
  5026. }
  5027.  
  5028. /*
  5029.  * Delete a hash node.  Some weirdness to free junk from macros.
  5030.  * More such weirdness will have to be added if you define more hash
  5031.  * types that need it.
  5032.  */
  5033.  
  5034. /* Note that the DEFINITION of a macro is removed from the hash table
  5035.    but its storage is not freed.  This would be a storage leak
  5036.    except that it is not reasonable to keep undefining and redefining
  5037.    large numbers of macros many times.
  5038.    In any case, this is necessary, because a macro can be #undef'd
  5039.    in the middle of reading the arguments to a call to it.
  5040.    If #undef freed the DEFINITION, that would crash.  */
  5041.  
  5042. delete_macro (hp)
  5043.      HASHNODE *hp;
  5044. {
  5045.  
  5046.   if (hp->prev != NULL)
  5047.     hp->prev->next = hp->next;
  5048.   if (hp->next != NULL)
  5049.     hp->next->prev = hp->prev;
  5050.  
  5051.   /* make sure that the bucket chain header that
  5052.      the deleted guy was on points to the right thing afterwards. */
  5053.   if (hp == *hp->bucket_hdr)
  5054.     *hp->bucket_hdr = hp->next;
  5055.  
  5056. #if 0
  5057.   if (hp->type == T_MACRO) {
  5058.     DEFINITION *d = hp->value.defn;
  5059.     struct reflist *ap, *nextap;
  5060.  
  5061.     for (ap = d->pattern; ap != NULL; ap = nextap) {
  5062.       nextap = ap->next;
  5063.       free (ap);
  5064.     }
  5065.     free (d);
  5066.   }
  5067. #endif
  5068.   free (hp);
  5069. }
  5070.  
  5071. /*
  5072.  * return hash function on name.  must be compatible with the one
  5073.  * computed a step at a time, elsewhere
  5074.  */
  5075. int
  5076. hashf (name, len, hashsize)
  5077.      register U_CHAR *name;
  5078.      register int len;
  5079.      int hashsize;
  5080. {
  5081.   register int r = 0;
  5082.  
  5083.   while (len--)
  5084.     r = HASHSTEP (r, *name++);
  5085.  
  5086.   return MAKE_POS (r) % hashsize;
  5087. }
  5088.  
  5089. /* Dump all macro definitions as #defines to stdout.  */
  5090.  
  5091. void
  5092. dump_all_macros ()
  5093. {
  5094.   int bucket;
  5095.  
  5096.   for (bucket = 0; bucket < HASHSIZE; bucket++) {
  5097.     register HASHNODE *hp;
  5098.  
  5099.     for (hp = hashtab[bucket]; hp; hp= hp->next) {
  5100.       if (hp->type == T_MACRO) {
  5101.     register DEFINITION *defn = hp->value.defn;
  5102.     struct reflist *ap;
  5103.     int offset;
  5104.     int concat;
  5105.  
  5106.  
  5107.     /* Print the definition of the macro HP.  */
  5108.  
  5109.     printf ("#define %s", hp->name);
  5110.     if (defn->nargs >= 0) {
  5111.       int i;
  5112.  
  5113.       printf ("(");
  5114.       for (i = 0; i < defn->nargs; i++) {
  5115.         dump_arg_n (defn, i);
  5116.         if (i + 1 < defn->nargs)
  5117.           printf (", ");
  5118.       }
  5119.       printf (")");
  5120.     }
  5121.  
  5122.     printf (" ");
  5123.  
  5124.     offset = 0;
  5125.     concat = 0;
  5126.     for (ap = defn->pattern; ap != NULL; ap = ap->next) {
  5127.       dump_defn_1 (defn->expansion, offset, ap->nchars);
  5128.       if (ap->nchars != 0)
  5129.         concat = 0;
  5130.       offset += ap->nchars;
  5131.       if (ap->stringify)
  5132.         printf (" #");
  5133.       if (ap->raw_before && !concat)
  5134.         printf (" ## ");
  5135.       concat = 0;
  5136.       dump_arg_n (defn, ap->argno);
  5137.       if (ap->raw_after) {
  5138.         printf (" ## ");
  5139.         concat = 1;
  5140.       }
  5141.     }
  5142.     dump_defn_1 (defn->expansion, offset, defn->length - offset);
  5143.     printf ("\n");
  5144.       }
  5145.     }
  5146.   }
  5147. }
  5148.  
  5149. /* Output to stdout a substring of a macro definition.
  5150.    BASE is the beginning of the definition.
  5151.    Output characters START thru LENGTH.
  5152.    Discard newlines outside of strings, thus
  5153.    converting funny-space markers to ordinary spaces.  */
  5154.  
  5155. dump_defn_1 (base, start, length)
  5156.      U_CHAR *base;
  5157.      int start;
  5158.      int length;
  5159. {
  5160.   U_CHAR *p = base + start;
  5161.   U_CHAR *limit = base + start + length;
  5162.  
  5163.   while (p < limit) {
  5164.     if (*p != '\n')
  5165.       putchar (*p);
  5166.     else if (*p == '\"' || *p =='\'') {
  5167.       U_CHAR *p1 = skip_quoted_string (p, limit, 0, 0, 0, 0);
  5168.       fwrite (p, p1 - p, 1, stdout);
  5169.       p = p1 - 1;
  5170.     }
  5171.     p++;
  5172.   }
  5173. }
  5174.  
  5175. /* Print the name of argument number ARGNUM of macro definition DEFN.
  5176.    Recall that DEFN->argnames contains all the arg names
  5177.    concatenated in reverse order with comma-space in between.  */
  5178.  
  5179. dump_arg_n (defn, argnum)
  5180.      DEFINITION *defn;
  5181.      int argnum;
  5182. {
  5183.   register U_CHAR *p = defn->argnames;
  5184.   while (argnum + 1 < defn->nargs) {
  5185.     p = (U_CHAR *) index (p, ' ') + 1;
  5186.     argnum++;
  5187.   }
  5188.  
  5189.   while (*p && *p != ',') {
  5190.     putchar (*p);
  5191.     p++;
  5192.   }
  5193. }
  5194.  
  5195. /* Initialize syntactic classifications of characters.  */
  5196.  
  5197. initialize_char_syntax ()
  5198. {
  5199.   register int i;
  5200.  
  5201.   /*
  5202.    * Set up is_idchar and is_idstart tables.  These should be
  5203.    * faster than saying (is_alpha (c) || c == '_'), etc.
  5204.    * Must do set up these things before calling any routines tthat
  5205.    * refer to them.
  5206.    */
  5207.   for (i = 'a'; i <= 'z'; i++) {
  5208.     is_idchar[i - 'a' + 'A'] = 1;
  5209.     is_idchar[i] = 1;
  5210.     is_idstart[i - 'a' + 'A'] = 1;
  5211.     is_idstart[i] = 1;
  5212.   }
  5213.   for (i = '0'; i <= '9'; i++)
  5214.     is_idchar[i] = 1;
  5215.   is_idchar['_'] = 1;
  5216.   is_idstart['_'] = 1;
  5217.   is_idchar['$'] = dollars_in_ident;
  5218.   is_idstart['$'] = dollars_in_ident;
  5219.  
  5220.   /* horizontal space table */
  5221.   is_hor_space[' '] = 1;
  5222.   is_hor_space['\t'] = 1;
  5223.   is_hor_space['\v'] = 1;
  5224.   is_hor_space['\f'] = 1;
  5225.  
  5226.   is_space[' '] = 1;
  5227.   is_space['\t'] = 1;
  5228.   is_space['\v'] = 1;
  5229.   is_space['\f'] = 1;
  5230.   is_space['\n'] = 1;
  5231. }
  5232.  
  5233. /* Initialize the built-in macros.  */
  5234.  
  5235. initialize_builtins ()
  5236. {
  5237.   install ("__LINE__", -1, T_SPECLINE, 0, -1);
  5238.   install ("__DATE__", -1, T_DATE, 0, -1);
  5239.   install ("__FILE__", -1, T_FILE, 0, -1);
  5240.   install ("__BASE_FILE__", -1, T_BASE_FILE, 0, -1);
  5241.   install ("__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, -1);
  5242.   install ("__VERSION__", -1, T_VERSION, 0, -1);
  5243.   install ("__TIME__", -1, T_TIME, 0, -1);
  5244.   if (!traditional) {
  5245.     DEFINITION *defn;
  5246. #ifdef ds3100
  5247.     U_CHAR *bp = (unsigned char *)"1";
  5248. #else
  5249.     U_CHAR bp[] = "1";
  5250. #endif
  5251.  
  5252.     /* 
  5253.      * __STDC__ is a T_MACRO instead of a T_CONST so it
  5254.      * can be #undef'ed
  5255.      */
  5256.     defn = collect_expansion(bp, bp + 1, -1, 0);
  5257.     install ("__STDC__", -1, T_MACRO, defn, -1);
  5258.   }
  5259.  
  5260. /*  install ("__GNU__", -1, T_CONST, 1, -1);  */
  5261. /*  This is supplied using a -D by the compiler driver
  5262.     so that it is present only when truly compiling with GNU C.  */
  5263. }
  5264.  
  5265. /*
  5266.  * process a given definition string, for initialization
  5267.  * If STR is just an identifier, define it with value 1.
  5268.  * If STR has anything after the identifier, then it should
  5269.  * be identifier-space-definition.
  5270.  */
  5271. make_definition (str)
  5272.      U_CHAR *str;
  5273. {
  5274.   FILE_BUF *ip;
  5275.   struct directive *kt;
  5276.   U_CHAR *buf, *p;
  5277.  
  5278.   buf = str;
  5279.   p = str;
  5280.   while (is_idchar[*p]) p++;
  5281.   if (*p == 0) {
  5282.     buf = (U_CHAR *) alloca (p - buf + 4);
  5283.     strcpy ((char *)buf, str);
  5284.     strcat ((char *)buf, " 1");
  5285.   }
  5286.   
  5287.   ip = &instack[++indepth];
  5288.   ip->fname = "*Initialization*";
  5289.  
  5290.   ip->buf = ip->bufp = buf;
  5291.   ip->length = strlen (buf);
  5292.   ip->lineno = 1;
  5293.   ip->macro = 0;
  5294.   ip->free_ptr = 0;
  5295.   ip->if_stack = if_stack;
  5296.  
  5297.   for (kt = directive_table; kt->type != T_DEFINE; kt++)
  5298.     ;
  5299.  
  5300.   /* pass NULL as output ptr to do_define since we KNOW it never
  5301.      does any output.... */
  5302.   do_define (buf, buf + strlen (buf) , NULL, kt);
  5303.   --indepth;
  5304. }
  5305.  
  5306. /* JF, this does the work for the -U option */
  5307. make_undef (str)
  5308.      U_CHAR *str;
  5309. {
  5310.   FILE_BUF *ip;
  5311.   struct directive *kt;
  5312.  
  5313.   ip = &instack[++indepth];
  5314.   ip->fname = "*undef*";
  5315.  
  5316.   ip->buf = ip->bufp = str;
  5317.   ip->length = strlen (str);
  5318.   ip->lineno = 1;
  5319.   ip->macro = 0;
  5320.   ip->free_ptr = 0;
  5321.   ip->if_stack = if_stack;
  5322.  
  5323.   for (kt = directive_table; kt->type != T_UNDEF; kt++)
  5324.     ;
  5325.  
  5326.   do_undef (str,str + strlen (str) - 1, NULL, kt);
  5327.   --indepth;
  5328. }
  5329.  
  5330. /* Add output to `deps_buffer' for the -M switch.
  5331.    STRING points to the text to be output.
  5332.    SIZE is the number of bytes, or 0 meaning output until a null.
  5333.    If SIZE is nonzero, we break the line first, if it is long enough.  */
  5334.  
  5335. deps_output (string, size)
  5336.      char *string;
  5337.      int size;
  5338. {
  5339. #ifndef MAX_OUTPUT_COLUMNS
  5340. #define MAX_OUTPUT_COLUMNS 75
  5341. #endif
  5342.   if (size != 0 && deps_column != 0
  5343.       && size + deps_column > MAX_OUTPUT_COLUMNS) {
  5344.     deps_output ("\\\n  ", 0);
  5345.     deps_column = 0;
  5346.   }
  5347.  
  5348.   if (size == 0)
  5349.     size = strlen (string);
  5350.  
  5351.   if (deps_size + size + 1 > deps_allocated_size) {
  5352.     deps_allocated_size = deps_size + size + 50;
  5353.     deps_allocated_size *= 2;
  5354.     deps_buffer = (char *) xrealloc (deps_buffer, deps_allocated_size);
  5355.   }
  5356.   bcopy (string, &deps_buffer[deps_size], size);
  5357.   deps_size += size;
  5358.   deps_column += size;
  5359.   deps_buffer[deps_size] = 0;
  5360. }
  5361.  
  5362. #ifndef BSD
  5363. #ifndef BSTRING
  5364.  
  5365. void
  5366. bzero (b, length)
  5367.      register char *b;
  5368.      register int length;
  5369. {
  5370. #ifdef VMS
  5371.   short zero = 0;
  5372.   long max_str = 65535;
  5373.  
  5374.   while (length > max_str) {
  5375.     (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
  5376.     length -= max_str;
  5377.     b += max_str;
  5378.   }
  5379.   (void) LIB$MOVC5 (&zero, &zero, &zero, &length, b);
  5380. #else
  5381.   while (length-- > 0)
  5382.     *b++ = 0;
  5383. #endif /* not VMS */
  5384. }
  5385.  
  5386. void
  5387. bcopy (b1, b2, length)
  5388.      register char *b1;
  5389.      register char *b2;
  5390.      register int length;
  5391. {
  5392. #ifdef VMS
  5393.   long max_str = 65535;
  5394.  
  5395.   while (length > max_str) {
  5396.     (void) LIB$MOVC3 (&max_str, b1, b2);
  5397.     length -= max_str;
  5398.     b1 += max_str;
  5399.     b2 += max_str;
  5400.   }
  5401.   (void) LIB$MOVC3 (&length, b1, b2);
  5402. #else
  5403.   while (length-- > 0)
  5404.     *b2++ = *b1++;
  5405. #endif /* not VMS */
  5406. }
  5407.  
  5408. int
  5409. bcmp (b1, b2, length)    /* This could be a macro! */
  5410.      register char *b1;
  5411.      register char *b2;
  5412.       register int length;
  5413. {
  5414. #ifdef VMS
  5415.    struct dsc$descriptor_s src1 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b1};
  5416.    struct dsc$descriptor_s src2 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b2};
  5417.  
  5418.    return STR$COMPARE (&src1, &src2);
  5419. #else
  5420.    while (length-- > 0)
  5421.      if (*b1++ != *b2++)
  5422.        return 1;
  5423.  
  5424.    return 0;
  5425. #endif /* not VMS */
  5426. }
  5427. #endif /* not BSTRING */
  5428. #endif /* not BSD */
  5429.  
  5430.  
  5431. void
  5432. fatal (str, arg)
  5433.      char *str, *arg;
  5434. {
  5435.   fprintf (stderr, "%s: ", progname);
  5436.   fprintf (stderr, str, arg);
  5437.   fprintf (stderr, "\n");
  5438.   exit (FATAL_EXIT_CODE);
  5439. }
  5440.  
  5441. /* More 'friendly' abort that prints the line and file.
  5442.    config.h can #define abort fancy_abort if you like that sort of thing.  */
  5443.  
  5444. void
  5445. fancy_abort ()
  5446. {
  5447.   fatal ("Internal gcc abort.");
  5448. }
  5449.  
  5450. void
  5451. perror_with_name (name)
  5452.      char *name;
  5453. {
  5454.   extern int errno, sys_nerr;
  5455.   extern char *sys_errlist[];
  5456.  
  5457.   fprintf (stderr, "%s: ", progname);
  5458.   if (errno < sys_nerr)
  5459.     fprintf (stderr, "%s: %s\n", name, sys_errlist[errno]);
  5460.   else
  5461.     fprintf (stderr, "%s: undocumented I/O error\n", name);
  5462.   errors++;
  5463. }
  5464.  
  5465. void
  5466. pfatal_with_name (name)
  5467.      char *name;
  5468. {
  5469.   perror_with_name (name);
  5470. #ifdef VMS
  5471.   exit (vaxc$errno);
  5472. #else
  5473.   exit (FATAL_EXIT_CODE);
  5474. #endif
  5475. }
  5476.  
  5477.  
  5478. void
  5479. memory_full ()
  5480. {
  5481.   fatal ("Memory exhausted.");
  5482. }
  5483.  
  5484.  
  5485. char *
  5486. xmalloc (size)
  5487.      int size;
  5488. {
  5489.   extern char *malloc ();
  5490.   register char *ptr = malloc (size);
  5491.   if (ptr != 0) return (ptr);
  5492.   memory_full ();
  5493.   /*NOTREACHED*/
  5494. }
  5495.  
  5496. char *
  5497. xrealloc (old, size)
  5498.      char *old;
  5499.      int size;
  5500. {
  5501.   extern char *realloc ();
  5502.   register char *ptr = realloc (old, size);
  5503.   if (ptr != 0) return (ptr);
  5504.   memory_full ();
  5505.   /*NOTREACHED*/
  5506. }
  5507.  
  5508. char *
  5509. xcalloc (number, size)
  5510.      int number, size;
  5511. {
  5512.   extern char *malloc ();
  5513.   register int total = number * size;
  5514.   register char *ptr = malloc (total);
  5515.   if (ptr != 0) {
  5516.     if (total > 100)
  5517.       bzero (ptr, total);
  5518.     else {
  5519.       /* It's not too long, so loop, zeroing by longs.
  5520.      It must be safe because malloc values are always well aligned.  */
  5521.       register long *zp = (long *) ptr;
  5522.       register long *zl = (long *) (ptr + total - 4);
  5523.       register int i = total - 4;
  5524.       while (zp < zl)
  5525.     *zp++ = 0;
  5526.       if (i < 0)
  5527.     i = 0;
  5528.       while (i < total)
  5529.     ptr[i++] = 0;
  5530.     }
  5531.     return ptr;
  5532.   }
  5533.   memory_full ();
  5534.   /*NOTREACHED*/
  5535. }
  5536.  
  5537. char *
  5538. savestring (input)
  5539.      char *input;
  5540. {
  5541.   int size = strlen (input);
  5542.   char *output = xmalloc (size + 1);
  5543.   strcpy (output, input);
  5544.   return output;
  5545. }
  5546.  
  5547. /* Get the file-mode and data size of the file open on FD
  5548.    and store them in *MODE_POINTER and *SIZE_POINTER.  */
  5549.  
  5550. int
  5551. file_size_and_mode (fd, mode_pointer, size_pointer)
  5552.      int fd;
  5553.      int *mode_pointer;
  5554.      long int *size_pointer;
  5555. {
  5556.   struct stat sbuf;
  5557.  
  5558.   if (fstat (fd, &sbuf) < 0) return (-1);
  5559.   if (mode_pointer) *mode_pointer = sbuf.st_mode;
  5560.   if (size_pointer) *size_pointer = sbuf.st_size;
  5561.   return 0;
  5562. }
  5563.  
  5564. #ifdef    VMS
  5565.  
  5566. /* Under VMS we need to fix up the "include" specification
  5567.    filename so that everything following the 1st slash is
  5568.    changed into its correct VMS file specification. */
  5569.  
  5570. hack_vms_include_specification (fname)
  5571.      char *fname;
  5572. {
  5573.   register char *cp, *cp1, *cp2;
  5574.   char Local[512];
  5575.   extern char *index (), *rindex ();
  5576.  
  5577.   /* Ignore leading "./"s */
  5578.   while (fname[0] == '.' && fname[1] == '/')
  5579.     strcpy (fname, fname+2);
  5580.   /* Look for the boundary between the VMS and UNIX filespecs */
  5581.   cp = rindex (fname, ']');    /* Look for end of dirspec. */
  5582.   if (cp == 0) cp == rindex (fname, '>'); /* ... Ditto            */
  5583.   if (cp == 0) cp == rindex (fname, ':'); /* Look for end of devspec. */
  5584.   if (cp) {
  5585.     cp++;
  5586.   } else {
  5587.     cp = index (fname, '/');    /* Look for the "/" */
  5588.   }
  5589.   /* See if we found that 1st slash */
  5590.   if (cp == 0) return;        /* Nothing to do!!! */
  5591.   if (*cp != '/') return;    /* Nothing to do!!! */
  5592.   /* Point to the UNIX filename part (which needs to be fixed!) */
  5593.   cp1 = cp+1;
  5594.   /* If the directory spec is not rooted, we can just copy
  5595.      the UNIX filename part and we are done */
  5596.   if (((cp - fname) > 2)
  5597.       && ((cp[-1] == ']') || (cp[-1] == '>'))
  5598.       && (cp[-2] != '.')) {
  5599.     strcpy (cp, cp1);
  5600.     return;
  5601.   }
  5602.   /* If there are no other slashes then the filename will be
  5603.      in the "root" directory.  Otherwise, we need to add
  5604.      directory specifications. */
  5605.   if (index (cp1, '/') == 0) {
  5606.     /* Just add "[000000]" as the directory string */
  5607.     strcpy (Local, "[000000]");
  5608.     cp2 = Local + strlen (Local);
  5609.   } else {
  5610.     /* Open the directory specification */
  5611.     cp2 = Local;
  5612.     *cp2++ = '[';
  5613.     /* As long as there are still subdirectories to add, do them. */
  5614.     while (index (cp1, '/') != 0) {
  5615.       /* If this token is "." we can ignore it */
  5616.       if ((cp1[0] == '.') && (cp1[1] == '/')) {
  5617.     cp1 += 2;
  5618.     continue;
  5619.       }
  5620.       /* Add a subdirectory spec. */
  5621.       if (cp2 != Local+1) *cp2++ = '.';
  5622.       /* If this is ".." then the spec becomes "-" */
  5623.       if ((cp1[0] == '.') && (cp1[1] == '.') && (cp[2] == '/')) {
  5624.     /* Add "-" and skip the ".." */
  5625.     *cp2++ = '-';
  5626.     cp1 += 3;
  5627.     continue;
  5628.       }
  5629.       /* Copy the subdirectory */
  5630.       while (*cp1 != '/') *cp2++= *cp1++;
  5631.       cp1++;            /* Skip the "/" */
  5632.     }
  5633.     /* Close the directory specification */
  5634.     *cp2++ = ']';
  5635.   }
  5636.   /* Now add the filename */
  5637.   while (*cp1) *cp2++ = *cp1++;
  5638.   *cp2 = 0;
  5639.   /* Now append it to the original VMS spec. */
  5640.   strcpy (cp, Local);
  5641.   return;
  5642. }
  5643. #endif    /* VMS */
  5644.  
  5645. #ifdef    VMS
  5646.  
  5647. /* These are the read/write replacement routines for
  5648.    VAX-11 "C".  They make read/write behave enough
  5649.    like their UNIX counterparts that CCCP will work */
  5650.  
  5651. int
  5652. read (fd, buf, size)
  5653.      int fd;
  5654.      char *buf;
  5655.      int size;
  5656. {
  5657. #undef    read    /* Get back the REAL read routine */
  5658.   register int i;
  5659.   register int total = 0;
  5660.  
  5661.   /* Read until the buffer is exhausted */
  5662.   while (size > 0) {
  5663.     /* Limit each read to 32KB */
  5664.     i = (size > (32*1024)) ? (32*1024) : size;
  5665.     i = read (fd, buf, i);
  5666.     if (i <= 0) {
  5667.       if (i == 0) return (total);
  5668.       return(i);
  5669.     }
  5670.     /* Account for this read */
  5671.     total += i;
  5672.     buf += i;
  5673.     size -= i;
  5674.   }
  5675.   return (total);
  5676. }
  5677.  
  5678. int
  5679. write (fd, buf, size)
  5680.      int fd;
  5681.      char *buf;
  5682.      int size;
  5683. {
  5684. #undef    write    /* Get back the REAL write routine */
  5685.   int i;
  5686.   int j;
  5687.  
  5688.   /* Limit individual writes to 32Kb */
  5689.   i = size;
  5690.   while (i > 0) {
  5691.     j = (i > (32*1024)) ? (32*1024) : i;
  5692.     if (write (fd, buf, j) < 0) return (-1);
  5693.     /* Account for the data written */
  5694.     buf += j;
  5695.     i -= j;
  5696.   }
  5697.   return (size);
  5698. }
  5699.  
  5700. #endif /* VMS */
  5701. @
  5702.  
  5703.  
  5704. 1.6
  5705. log
  5706. @
  5707. Added ifdef to allow the mips compiler to compile the file.
  5708. @
  5709. text
  5710. @d2 1
  5711. a2 1
  5712. Copyright (C) 1986, 1987, Free Software Foundation, Inc.
  5713. d6 4
  5714. a9 1
  5715.                NO WARRANTY
  5716. d11 4
  5717. a14 93
  5718.   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  5719. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  5720. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  5721. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  5722. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  5723. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5724. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  5725. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  5726. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  5727. CORRECTION.
  5728.  
  5729.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  5730. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  5731. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  5732. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  5733. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  5734. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  5735. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  5736. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  5737. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  5738. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  5739.  
  5740.         GENERAL PUBLIC LICENSE TO COPY
  5741.  
  5742.   1. You may copy and distribute verbatim copies of this source file
  5743. as you receive it, in any medium, provided that you conspicuously
  5744. and appropriately publish on each copy a valid copyright notice
  5745. "Copyright (C) 1987, Free Software Foundation"; and include
  5746. following the copyright notice a verbatim copy of the above disclaimer
  5747. of warranty and of this License.  You may charge a distribution fee for the
  5748. physical act of transferring a copy.
  5749.  
  5750.   2. You may modify your copy or copies of this source file or
  5751. any portion of it, and copy and distribute such modifications under
  5752. the terms of Paragraph 1 above, provided that you also do the following:
  5753.  
  5754.     a) cause the modified files to carry prominent notices stating
  5755.     that you changed the files and the date of any change; and
  5756.  
  5757.     b) cause the whole of any work that you distribute or publish,
  5758.     that in whole or in part contains or is a derivative of this
  5759.     program or any part thereof, to be licensed at no charge to all
  5760.     third parties on terms identical to those contained in this
  5761.     License Agreement (except that you may choose to grant more extensive
  5762.     warranty protection to some or all third parties, at your option).
  5763.  
  5764.     c) You may charge a distribution fee for the physical act of
  5765.     transferring a copy, and you may at your option offer warranty
  5766.     protection in exchange for a fee.
  5767.  
  5768. Mere aggregation of another unrelated program with this program (or its
  5769. derivative) on a volume of a storage or distribution medium does not bring
  5770. the other program under the scope of these terms.
  5771.  
  5772.   3. You may copy and distribute this program (or a portion or derivative
  5773. of it, under Paragraph 2) in object code or executable form under the terms
  5774. of Paragraphs 1 and 2 above provided that you also do one of the following:
  5775.  
  5776.     a) accompany it with the complete corresponding machine-readable
  5777.     source code, which must be distributed under the terms of
  5778.     Paragraphs 1 and 2 above; or,
  5779.  
  5780.     b) accompany it with a written offer, valid for at least three
  5781.     years, to give any third party free (except for a nominal
  5782.     shipping charge) a complete machine-readable copy of the
  5783.     corresponding source code, to be distributed under the terms of
  5784.     Paragraphs 1 and 2 above; or,
  5785.  
  5786.     c) accompany it with the information you received as to where the
  5787.     corresponding source code may be obtained.  (This alternative is
  5788.     allowed only for noncommercial distribution and only if you
  5789.     received the program in object code or executable form alone.)
  5790.  
  5791. For an executable file, complete source code means all the source code for
  5792. all modules it contains; but, as a special exception, it need not include
  5793. source code for modules which are standard libraries that accompany the
  5794. operating system on which the executable file runs.
  5795.  
  5796.   4. You may not copy, sublicense, distribute or transfer this program
  5797. except as expressly provided under this License Agreement.  Any attempt
  5798. otherwise to copy, sublicense, distribute or transfer this program is void and
  5799. your rights to use the program under this License agreement shall be
  5800. automatically terminated.  However, parties who have received computer
  5801. software programs from you with this License Agreement will not have
  5802. their licenses terminated so long as such parties remain in full compliance.
  5803.  
  5804.   5. If you wish to incorporate parts of this program into other free
  5805. programs whose distribution conditions are different, write to the Free
  5806. Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  5807. worked out a simple rule that can be stated here, but we will often permit
  5808. this.  We will be guided by the two goals of preserving the free status of
  5809. all derivatives of our free software and of promoting the sharing and reuse of
  5810. software.
  5811. d16 3
  5812. d31 1
  5813. d45 1
  5814. a45 5
  5815.  
  5816. #ifdef sun4
  5817. #include <alloca.h>
  5818. #endif
  5819.  
  5820. d66 1
  5821. a66 1
  5822. extern char *getenv (), *malloc();
  5823. d71 5
  5824. d78 1
  5825. a78 1
  5826.   do_elif (), do_endif (), do_sccs ();
  5827. d83 2
  5828. a84 2
  5829. char *xmalloc (), *xrealloc (), *xcalloc ();
  5830. void fatal (), pfatal_with_name (), perror_with_name ();
  5831. d86 2
  5832. d91 2
  5833. d198 7
  5834. d206 3
  5835. d225 1
  5836. a225 1
  5837. struct directory_stack
  5838. d227 1
  5839. a227 1
  5840.     struct directory_stack *next;
  5841. d243 1
  5842. a243 1
  5843. struct directory_stack include_defaults[] =
  5844. d248 1
  5845. a248 1
  5846. #else      
  5847. d262 1
  5848. a262 1
  5849. struct directory_stack cplusplus_include_defaults[] =
  5850. a270 2
  5851.     /* Borrow AT&T C++ head files, if available.  */
  5852.     { &cplusplus_include_defaults[2], "/usr/include/CC" },
  5853. d272 1
  5854. a272 1
  5855.     { &cplusplus_include_defaults[3], GCC_INCLUDE_DIR },
  5856. d275 2
  5857. a276 1
  5858.     { &cplusplus_include_defaults[1], "GNU_CC_INCLUDE:" },
  5859. d278 1
  5860. a278 1
  5861.     { &cplusplus_include_defaults[2], "SYS$SYSROOT:[SYSLIB.]" },
  5862. d284 1
  5863. a284 1
  5864. struct directory_stack *include = 0;    /* First dir to search */
  5865. d286 8
  5866. a293 2
  5867. struct directory_stack *first_bracket_include = 0;
  5868. struct directory_stack *last_include = 0;    /* Last in chain */
  5869. a361 2
  5870. #if 0
  5871.  /* cpp can pass #pragma through unchanged.  */
  5872. a362 1
  5873. #endif
  5874. d373 2
  5875. d377 1
  5876. a377 1
  5877.  T_CONST,    /* Constant value, (no longer used). */
  5878. d427 1
  5879. d447 1
  5880. a447 3
  5881. #if 0
  5882.   {  6, do_pragma, "pragma", T_PRAGMA},
  5883. #endif
  5884. d559 17
  5885. d614 1
  5886. a614 1
  5887.     fatal ("Usage: %s [switches] input output\n", argv[0]);
  5888. d625 2
  5889. d633 3
  5890. a635 1
  5891.       fatal ("Output filename specified twice\n");
  5892. d646 6
  5893. a651 2
  5894.     traditional = 1;
  5895.     dollars_in_ident = 1;
  5896. a660 1
  5897.       no_trigraphs = 0;
  5898. d664 2
  5899. a667 1
  5900.       no_trigraphs = 0;
  5901. d695 2
  5902. d709 2
  5903. a725 4
  5904.       case 'T':            /* Enable ANSI trigraphs */
  5905.     no_trigraphs = 0;
  5906.     break;
  5907.  
  5908. d732 1
  5909. a732 1
  5910.       struct directory_stack *dirtmp;
  5911. d737 2
  5912. a738 2
  5913.         dirtmp = (struct directory_stack *)
  5914.           xmalloc (sizeof (struct directory_stack));
  5915. d747 2
  5916. d788 1
  5917. a788 1
  5918.     fatal ("Invalid option `%s'\n", argv[i]);
  5919. d795 1
  5920. a795 1
  5921.      directory stack. */
  5922. d797 1
  5923. a797 1
  5924.       machine = getenv("MACHINE");
  5925. d800 16
  5926. a815 10
  5927.       include_defaults[0].fname = malloc((unsigned) (strlen(machine) + 30));
  5928.       sprintf(include_defaults[0].fname, "/sprite/lib/include/%s.md", machine);
  5929.       include_defaults[0].next = &include_defaults[1];
  5930.       cplusplus_include_defaults[0].fname = include_defaults[0].fname;
  5931.       cplusplus_include_defaults[0].next = &cplusplus_include_defaults[1];
  5932.   } else {
  5933.       include_defaults[0].fname = include_defaults[1].fname;
  5934.       include_defaults[1].fname = NULL;
  5935.       cplusplus_include_defaults[0].fname = cplusplus_include_defaults[1].fname;
  5936.       cplusplus_include_defaults[1].fname = NULL;
  5937. d861 4
  5938. d1056 1
  5939. a1056 1
  5940.   output_line_command (fp, &outbuf, 0);
  5941. d1162 1
  5942. a1162 1
  5943.     warning("file contains %d trigraph(s)", (fptr - bptr) / 2);
  5944. d1673 1
  5945. a1673 1
  5946.        Here While means any horizontal whitespace character.
  5947. d1724 1
  5948. a1724 1
  5949.     output_line_command (ip, op, 1);
  5950. d1841 4
  5951. d1847 1
  5952. d1870 20
  5953. d2013 10
  5954. a2032 8
  5955.   /* Set up to receive the output.  */
  5956.  
  5957.   obuf.length = length * 2 + 100; /* Usually enough.  Why be stingy?  */
  5958.   obuf.bufp = obuf.buf = (U_CHAR *) xmalloc (obuf.length);
  5959.   obuf.fname = 0;
  5960.   obuf.macro = 0;
  5961.   obuf.free_ptr = 0;
  5962.  
  5963. d2293 19
  5964. d2342 1
  5965. d2361 27
  5966. a2387 2
  5967.     buf = (char *) alloca (3 + strlen (ip->fname));
  5968.     sprintf (buf, "\"%s\"", ip->fname);
  5969. d2477 2
  5970. a2478 2
  5971.   struct directory_stack *stackp = include; /* Chain of dirs to search */
  5972.   struct directory_stack dsp[1];    /* First in chain, if #include "..." */
  5973. d2591 5
  5974. a2619 6
  5975.   /* For -M, print the name of the included file.  */
  5976.   if (print_deps > system_header_p) {
  5977.     deps_output (fname, strlen (fname));
  5978.     deps_output (" ", 0);
  5979.   }
  5980.  
  5981. d2623 52
  5982. a2674 2
  5983.     error ("can't find include file `%s'", fname);
  5984.   } else {
  5985. d2676 4
  5986. d2698 2
  5987. d2770 1
  5988. a2770 1
  5989.   output_line_command (fp, op, 0);
  5990. d2773 1
  5991. a2773 1
  5992.   output_line_command (&instack[indepth], op, 0);
  5993. d2777 3
  5994. a2780 3
  5995.   if (!success) {
  5996.     perror_with_name (fname);
  5997.   }
  5998. d2920 1
  5999. a2920 1
  6000.     strcpy (msg + sym_length, " redefined");
  6001. d2951 1
  6002. a2951 1
  6003.   if (strcmp (d1->argnames, d2->argnames))
  6004. a3272 18
  6005. #ifdef DEBUG
  6006. /*
  6007.  * debugging routine ---- return a ptr to a string containing
  6008.  *   first n chars of s.  Returns a ptr to a static object
  6009.  *   since I happen to know it will fit.
  6010.  */
  6011. U_CHAR *
  6012. prefix (s, n)
  6013.      U_CHAR *s;
  6014.      int n;
  6015. {
  6016.   static U_CHAR buf[1000];
  6017.   bcopy (s, buf, n);
  6018.   buf[n] = '\0';        /* this should not be necessary! */
  6019.   return buf;
  6020. }
  6021. #endif
  6022.  
  6023. d3288 1
  6024. d3337 15
  6025. a3351 2
  6026.       error ("invalid format #line command");
  6027.       return;
  6028. d3378 1
  6029. a3378 1
  6030.   output_line_command (ip, op, 0);
  6031. d3402 1
  6032. a3402 1
  6033.  
  6034. d3422 37
  6035. d3552 1
  6036. a3552 1
  6037.       output_line_command (ip, op, 1);
  6038. d3644 1
  6039. a3644 1
  6040.     output_line_command (ip, &outbuf, 1);
  6041. d3846 1
  6042. a3846 1
  6043.     output_line_command (ip, op, 1);
  6044. d3870 1
  6045. a3870 1
  6046.     output_line_command (&instack[indepth], op, 1);
  6047. d4063 1
  6048. d4067 1
  6049. a4067 1
  6050. output_line_command (ip, op, conditional)
  6051. d4070 1
  6052. d4099 1
  6053. a4099 1
  6054.   sprintf (line_cmd_buf, "#line %d \"%s\"\n", ip->lineno, ip->fname);
  6055. d4101 1
  6056. a4101 1
  6057.   sprintf (line_cmd_buf, "# %d \"%s\"\n", ip->lineno, ip->fname);
  6058. d4103 2
  6059. d4106 1
  6060. d4141 1
  6061. d4152 2
  6062. d4183 3
  6063. a4185 1
  6064.       if (parse_error = macarg ((i < nargs || (nargs == 0 && i == 0)) ? &args[i] : 0))
  6065. d4193 2
  6066. a4194 1
  6067.     if (nargs == 0 && i == 1) {
  6068. d4198 17
  6069. a4214 5
  6070.       if (bp != lim)
  6071.     error ("arguments given to macro `%s'", hp->name);
  6072.     } else if (i < nargs)
  6073.       error ("only %d args to macro `%s'", i, hp->name);
  6074.     else if (i > nargs)
  6075. d4277 1
  6076. a4277 1
  6077.         /* Special markers Newline Space and Newline Newline
  6078. d4279 1
  6079. a4279 1
  6080.         if (c == '\n') {
  6081. d4285 10
  6082. a4294 2
  6083.         if (is_space[c]) {
  6084.           while (c = arg->raw[i+1], is_space[c]) i++;
  6085. d4315 1
  6086. a4315 1
  6087.           sprintf (&xbuf[totlen], "\\%03o", (unsigned int) c);
  6088. d4400 6
  6089. a4405 1
  6090.     hp->type = T_DISABLED;
  6091. d4730 1
  6092. a4730 1
  6093.      U_CHAR *msg;
  6094. d4749 28
  6095. d4780 1
  6096. a4780 1
  6097.      U_CHAR *msg;
  6098. d4801 1
  6099. a4801 1
  6100.      U_CHAR *msg;
  6101. d5037 1
  6102. a5092 1
  6103.   return NULL;
  6104. d5186 2
  6105. d5191 1
  6106. a5191 1
  6107.       DEFINITION *defn;
  6108. d5193 1
  6109. a5193 1
  6110.       U_CHAR *bp = (unsigned char *)"1";
  6111. d5195 1
  6112. a5195 1
  6113.       U_CHAR bp[] = "1";
  6114. d5198 6
  6115. a5203 6
  6116.       /* 
  6117.        * __STDC__ is a T_MACRO instead of a T_CONST so it
  6118.        * can be #undef'ed
  6119.        */
  6120.       defn = collect_expansion(bp, bp + 1, -1, 0);
  6121.       install ("__STDC__", -1, T_MACRO, defn, -1);
  6122. d5229 2
  6123. a5230 2
  6124.     strcpy (buf, str);
  6125.     strcat (buf, " 1");
  6126. d5232 1
  6127. a5232 1
  6128.  
  6129. d5285 5
  6130. a5289 1
  6131.   if (size != 0 && deps_column > 50) {
  6132. d5387 9
  6133. d5405 1
  6134. a5405 1
  6135.     fprintf (stderr, "%s for `%s'\n", sys_errlist[errno], name);
  6136. d5407 2
  6137. a5408 1
  6138.     fprintf (stderr, "undocumented error for `%s'\n", name);
  6139. d5416 3
  6140. d5420 1
  6141. d5483 9
  6142. @
  6143.  
  6144.  
  6145. 1.5
  6146. log
  6147. @looks like Bob added include of alloca.h -- John
  6148. @
  6149. text
  6150. @d4993 3
  6151. d4997 1
  6152. @
  6153.  
  6154.  
  6155. 1.4
  6156. log
  6157. @Fixed __STDC__ macro so it can be dereferenced.
  6158. @
  6159. text
  6160. @d127 5
  6161. a131 1
  6162.   
  6163. @
  6164.  
  6165.  
  6166. 1.3
  6167. log
  6168. @llooks in machine dependent include directories first
  6169. @
  6170. text
  6171. @d4987 12
  6172. a4998 2
  6173.   if (!traditional)
  6174.     install ("__STDC__", -1, T_MACRO, 1, -1);
  6175. @
  6176.  
  6177.  
  6178. 1.2
  6179. log
  6180. @*** empty log message ***
  6181. @
  6182. text
  6183. @d309 1
  6184. a310 1
  6185.     { 0, 0 },
  6186. d328 1
  6187. a329 1
  6188.     { 0, 0 },
  6189. d833 2
  6190. a834 2
  6191.       include_defaults[1].fname = malloc((unsigned) (strlen(machine) + 30));
  6192.       sprintf(include_defaults[1].fname, "/sprite/lib/include/%s.md", machine);
  6193. d836 1
  6194. a836 1
  6195.       cplusplus_include_defaults[1].fname = include_defaults[1].fname;
  6196. d838 5
  6197. @
  6198.  
  6199.  
  6200. 1.1
  6201. log
  6202. @Initial revision
  6203. @
  6204. text
  6205. @a108 19
  6206. #ifdef EMACS
  6207. #define NO_SHORTNAMES
  6208. #include "../src/config.h"
  6209. #ifdef open
  6210. #undef open
  6211. #undef read
  6212. #undef write
  6213. #endif /* open */
  6214. #endif /* EMACS */
  6215.  
  6216. #ifndef EMACS
  6217. #include "config.h"
  6218. #endif /* not EMACS */
  6219.  
  6220. /* In case config.h defines these.  */
  6221. #undef bcopy
  6222. #undef bzero
  6223. #undef bcmp
  6224.  
  6225. d148 1
  6226. a148 1
  6227. extern char *getenv ();
  6228. d297 9
  6229. d308 4
  6230. d321 1
  6231. d327 4
  6232. d345 1
  6233. d436 1
  6234. a436 1
  6235.  T_CONST,    /* Constant value, used by `__STDC__' */
  6236. d595 1
  6237. d813 7
  6238. d826 15
  6239. d1086 6
  6240. a1091 1
  6241.   else if (print_deps) {
  6242. a1098 3
  6243.   } else if (! inhibit_output) {
  6244.     if (write (fileno (stdout), outbuf.buf, outbuf.bufp - outbuf.buf) < 0)
  6245.       fatal ("I/O error on output");
  6246. d1482 8
  6247. a1489 1
  6248.       if (!traditional)
  6249. d2105 7
  6250. d3050 3
  6251. a3052 1
  6252.     if (expected_delimiter != '\0' && p < limit) {
  6253. d4983 1
  6254. a4983 1
  6255.     install ("__STDC__", -1, T_CONST, 1, -1);
  6256. d5010 1
  6257. a5010 1
  6258.   
  6259. @
  6260.